Another Salesforce blog!!!

Salesforce, Apex


getobject name by

String sObjectType; if(Trigger.New != null) sObjectType = Trigger.New.getSobjectType().getDescribe().getName(); else if(Trigger.Old != null) sObjectType = Trigger.Old.getSobjectType().getDescribe().getName(); if(sObjectType == ‘Exhibit__c’){ Favorite

Trigger: Adding Related Records

This trigger adds a related opportunity for each new or updated account if no opportunity is already associated with the account. The trigger first performs a SOQL query to get all child opportunities for the accounts that the trigger fired on. Next, the trigger iterates over the list of sObjects in Trigger.New to get each […]

How to test for an exception(‘addError’) in a Trigger

I have a trigger, which detects error conditions and feeds errors to the class or field. This gives a nice result interactively, in the GUI. But how do I write test code to catch these errors ? Is there a System.AssertException(), or the equivalent ? The idea is to: a. Write code in the test […]

How do I control recursive Triggers

Link: Apex Trigger Debugging: Solving the Hard Problems Favorite

Trigger event

trigger changeForecastCategory on Opportunity (after update) { // Create empty opportunity list List<Opportunity> oppsToUpdate = new List<Opportunity>(); //Create empty set Set<Id> oppIds = new Set<Id>(); // Interate selected opp records for (Opportunity opp :{ oppIds.add(; } // Fetch selected records List<Opportunity> opportunityList = [select Id, OwnerId, ForecastCategoryName, CA__Forecast__c, CA__Debug_MassUpdate__c from Opportunity where Id in:oppIds]; […]