Find your content:

Search form

You are here

Approval process with trigger

 
Share

Can you please give me a demo about a triggred approval process once a record is created. I cant find a documentation on the net

Thank you


Attribution to: LoveLace

Possible Suggestion/Solution #1

Here's a trigger on Account that submits an approval process if the Rating is Cold.

trigger AccountRecordLock on Account (after update, after insert) {
  for (Account a : Trigger.New) {
    if (a.Rating == 'Cold') {
      // Create an approval request for the account
      Approval.ProcessSubmitRequest req1 =
      new Approval.ProcessSubmitRequest();
      req1.setComments('Automatic submit.');
      req1.setObjectId(a.id);

      // Submit the approval request for the account
      Approval.ProcessResult result = Approval.process(req1);
    }
  }
}

Attribution to: Daniel Hoechst

Possible Suggestion/Solution #2

You need to use an APEX trigger. Here's a good example:

http://blog.jeffdouglas.com/2010/01/04/automating-salesforce-approval-processes-with-apex-triggers/


Attribution to: Guy Clairbois

Possible Suggestion/Solution #3

trigger AccountRecordLock on Account (after update, after insert) {
 List<Approval.ProcessSubmitRequest> lstprocess=new List<Approval.ProcessSubmitRequest>();
 for (Account a : Trigger.New) {
    if (a.Rating == 'Cold') {
  // Create an approval request for the account
  Approval.ProcessSubmitRequest req1 =
  new Approval.ProcessSubmitRequest();
  req1.setComments('Automatic submit.');
  req1.setObjectId(a.id);
  lstprocess.add(req1);
}    
    // Submit the approval request for the account
       List<Approval.ProcessResult> resultlist = Approval.process(lstprocess);
 }

Bulkified version of the code for approval process in Trigger


Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30822

My Block Status

My Block Content