2

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

5

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);
    }
  }
}
  • I think we can bulkify the same code by using collections .You may like to enhance the same – Mohith Shrivastava Mar 25 '14 at 3:02
  • I'm not aware of a way to bulkify Approval.process. You are right that it does count against DML limits, so that is something to watch out for. – Daniel Hoechst Mar 25 '14 at 3:17
0

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/

0
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.