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
sfdc007sfdc007 

Apex Test class help needed for approval process logic

Hi,
 
MY APEX CLASS CODE :

for(ProcessInstanceStep pInst : [Select OriginalActorId, ActorId, StepStatus From ProcessInstanceStep where ProcessInstance.TargetObjectId=:oNew.id  order by CreatedDate desc limit 1] ) 
                {
                    If(pInst.OriginalActorId <> pInst.ActorId)
                    {
                        string strsub;  
                        String body;
                        user usr=[select id,email from user where id=:pInst.OriginalActorId];
                        user usr1=[select id,name from user where id=:pInst.ActorId];

                        if(pInst.StepStatus=='Approved')
                        {
                            strsub = oNew.Name+' has been approved by  '+usr1.name;
                            body = '<p>'+oNew.Name+' has been approved by  '+usr1.name+' on your behalf on '+system.now()+'. </p>' ;
                        }
                        if(pInst.StepStatus=='Rejected')
                        {
                            strsub = oNew.Name+' has been rejected by  '+usr1.name;
                            body = '<p>'+oNew.Name+' has been rejected by  '+usr1.name+' on your behalf on '+system.now()+'. </p>' ;
                        }

                        List<Messaging.SingleEmailMessage> mailMessages = new List<Messaging.SingleEmailMessage>();
                        String[] toAddresses = new String[]{}; 
                        toAddresses.add(usr.email);
                        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                        mail.setToAddresses(toAddresses);
                        mail.setReplyTo('no-reply@verizon.com');
                        mail.setSubject(strsub);
                        URL currentUrl = URL.getCurrentRequestUrl();
                        URL curl = new URL(URL.getSalesforceBaseUrl().toExternalForm());
                        System.debug('currentUrl:'+currentUrl);
                        System.debug('curl:'+curl);
                        String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + oNew.Id;
                        System.debug('fullRecordURL:'+fullRecordURL);
                         // Add lead ids to body
                         body = body + '<br> Link to '+oNew.SFDC_Opportunity_ID__c+'-';
                         body = body + ': ' +fullRecordURL;
                         mail.setHtmlBody (body);
                         mailMessages.add(mail);
                         if(!mailMessages.isEmpty())
                         Messaging.sendEmail(mailMessages);
                    }
                }

I am having a apex class which is calling a approval process , where i need help on it to cover that part ,

i am not able to cover that part, Kindly help me on this


 
Suraj GharatSuraj Gharat
In your test method you need to submit a record to approval, before calling this method.