function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amber090Amber090 

Create Trigger Crash Course?

I need to create a trigger to kick off a workflow when a field value changes.  SInce the field that's being updated is a formula field, a standard workflow rule doesn't work.

Can someone give me a crash course/instructions to create a trigger to kick off a workflow if a field value changes?
Abhishek BansalAbhishek Bansal
Hi,

You can use the below code :
trigger kickOffWorkflow on CustomObject__c(before update){
	for(CustomObject__c newRecord : trigger.new){
		CustomObject__c oldRecord = trigger.oldMap.get(newRecord);
		if(oldRecord.CustomField__c != newRecord.CustomField__c){
			//Write your logic here 
		}
	}
}
//Please replace following varibales :
// 1. CustomObject__c with API name of your custom object on which you want to execute trigger
// 2. CustomField__c with API name of your field on change of which you want to perform some action
Please adjust your requirements in above trigger accordingly and let me know if you need more help on this.

Thanks,
Abhishek