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
Sanjay92062Sanjay92062 

How to fire the approval process when the fields are updated?

Hi,
I am looking to fire the approval process when any fields are updated with new values.is it possible?
Thanks in Advance.
 
AnudeepAnudeep (Salesforce Developers) 
I believe you have to write a trigger for that on record update. Here is an example
 
trigger updateforgetexpense on Expenses__c (after update) {
	for(Exxpenses__c expense : trigger.new){
		if(expense.Expense_Status__c == 'Draft'){
			// create the new approval request to submit
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(expense.Id);
            // submit the approval request for processing
            Approval.ProcessResult result = Approval.process(req);
            // display if the reqeust was successful
            System.debug('Submitted for approval successfully: '+result.isSuccess());
		}
	}
}

NOTE: The code provided is an example. You'll need to review and make modifications for your organization.

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Sanjay92062Sanjay92062
Hi Anudeep, thank you for your reply.
But i am facing below error.

User-added image

Actually,i am approving the record by another approval process.

1)Approval process for sending to Approval.If the record is Approved, if any changes will happen in Approved records, then only i want to fire the trigger and update the status as Changed.

Can we do that? Please suggest.
AnudeepAnudeep (Salesforce Developers) 
Recommend checking solution listed here