Sunday, July 21, 2013

Basic For Loop

Below is a basic example of a for loop. I always seem to need to need this and forget the exact context.


trigger OpportunitySubmitForApproval on Opportunity (after update) {
 
 for (Integer i = 0; i < Trigger.new.size(); i++) {
 
  if (Trigger.old[i].Probability < 30 && Trigger.new[i].Probability >= 30) {
 
   // create the new approval request to submit
   Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
   req.setComments('Submitted for approval. Please approve.');
   req.setObjectId(Trigger.new[i].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());
 
  }
 
 }
 
}

No comments:

Post a Comment