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
mahe_developermahe_developer 

Test Method for Approval process

Hi,

 

      I wrote trigger on Lead for auto firing of  'Submit for Approval' request once the Lead is Qualified, its working fine in Sandbox , how to write test method for this trigger, Can anybody send the sample test methods.

 

Thanks In Advance....

______________________________________________________________________________

 

trigger trigger_auto_request on Lead (after insert,after update) {
    {
 
       for (Integer i = 0; i < Trigger.new.size(); i++) 
           {
                if (Trigger.new[i].status =='Qualified' ) 
                    {
                         Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                         req.setComments('Submitted for approval. Please approve.');
                         req.setObjectId(Trigger.new[i].Id);
                         Approval.ProcessResult result = Approval.process(req);
                         System.debug('Submitted for approval successfully: '+result.isSuccess());
 
                    }
 
           }
 
    }

}
_____________________________________________________________________________________

 

Mahesh...........

Bhawani SharmaBhawani Sharma

You only need create the lead records with the status =='Qualified'  and then you can check the request status in Process Instance object.