+ Start a Discussion
ElectronElectron 

Is there possible to specific how we trigger an APEX trigger?

I checked most example triggers, they works on the scenario, such as before insert, after update or something else.
Does it means, no matter what kind action we do, Salesforce will check all triggers that related to the object?
 
Is it low efficient, and will it slow the system running?
If yes, could we specific the trigger to specific field change?
 
I know we can detect the filed change by 
If(field change)

 

Could we make same thing to limit trigger? or we needn't to do it.
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Salesforce will check all triggers related to the object, as each of the triggers fires at a different point of the order of execution. The platform doesn't make a decision about whether to run the trigger or not - that is up to you to check if you need to proceed with your trigger based on the records being processed.

 

Your trigger code should ensure that it is not taking action unless it absolutely has to, by checking the field values that have changed for example.

All Answers

Devendra@SFDCDevendra@SFDC

Hi,

 

You can try something like below, which will allow you to execute some code based on condition:

 

trigger TriggerEx on Case (before update){
	for(Case newCase : Trigger.New){
		Case oldCase = Trigger.oldMap.get(newCase.Id);
		if(oldCase.Field != newCase.Field){
			// Execute the code when Field value changes
			// This trigger will not execute every time
		}
	}
}

 

bob_buzzardbob_buzzard

Salesforce will check all triggers related to the object, as each of the triggers fires at a different point of the order of execution. The platform doesn't make a decision about whether to run the trigger or not - that is up to you to check if you need to proceed with your trigger based on the records being processed.

 

Your trigger code should ensure that it is not taking action unless it absolutely has to, by checking the field values that have changed for example.

This was selected as the best answer
ElectronElectron

Hi Bob,

Thank you so much, you solve all my questions, it's great to have you in this community.