Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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);
    }
  }
}
share|improve this answer
    
I think we can bulkify the same code by using collections .You may like to enhance the same –  Mohith Shrivastava Mar 25 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 at 3:17

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/

share|improve this answer
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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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