Wednesday, 20 July 2016

How to create Custom setting and retrieve the records from Custom setting object and its feilds.


Step 1: Create New Object in Custom setting.
Step 2: create new custom Fields what you require.
Step 3: Create records in Custom setting object in "Manage"

use the following code in the apex classes to get values

  list<(custom object api)> trtd = (custom object api).getall().values();

for Example:

list<US_Holidays__c> trtd = US_Holidays__c.getall().values();

Tuesday, 19 July 2016

How to avoid Recursive trigger

DescriptionMany Developers face this issue because of recursive trigger, or recursive update trigger. For example in 'after update' trigger, Developer is performing update operation and this lead to recursive call.
ResolutionIn order to avoid the situation of recursive call, make sure your trigger is getting executed only one time. To do so, you can create a class with a static boolean variable with default value true.

In the trigger, before executing your code keep a check that the variable is true or not.

Once you check make the variable false.



Class code :

public Class checkRecursive{
    private static boolean run = true;
    public static boolean runOnce(){
    if(run){
     run=false;
     return true;
    }else{
        return run;
    }
    }
}


Trigger code :

trigger updateTrigger on anyObject(after update) {

    if(checkRecursive.runOnce())
    {
    //write your code here          
    }

}



Reference Link: https://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US