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
ManvithaManvitha 

how to write test class for this approval controller .Can anyone help lease

public class ApprovalProcessController{
     public static String generateApprovalURL(String recordID){
         String url='';
         List<ProcessInstanceWorkitem> workItemLst = [SELECT id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId=:recordID];
            if(workItemLst.size() > 0){
               url='https://'+ System.URL.getSalesforceBaseUrl().getHost() + '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + workItemLst[0].id;
            }
        return url;
     }
    
     public static String getQuoteNames(String recordID){
         String Name;
       // List<Quote__c> quote = [select Id,Name FROM Quote__c WHERE Id=:recordID];
         for(Quote__c quote:[select Id,Name FROM Quote__c WHERE Id=:recordID]){
             Name=quote.Name;
         }
        return Name;
    }
}
SwethaSwetha (Salesforce Developers) 
HI Manasa,
The below code would give 45% coverage. 
@isTest
public class ApprovalClass_Test {
    static testMethod void approvetest(){
        Quote__c q = new Quote__c();
        q.Name = 'Test quote';
        insert q;
        ApprovalProcessController.getQuoteNames(q.id);       
        
    }   
}

While I am working on the complete 100% coverage snippet, you can refer below links
https://salesforce.stackexchange.com/questions/17981/processinstanceworkitems-not-created-when-running-an-approval-process-unit-test
https://salesforce.stackexchange.com/questions/107515/unable-to-cover-test-class-on-approval-process-69-covered-only
https://salesforce.stackexchange.com/questions/148768/how-to-unit-test-query-processinstanceworkitem-without-a-defined-approval-proces

If this information helps, please mark the answer as best. Thank you
mukesh guptamukesh gupta
Hi Mansa,

Please follow below code:-
 
@isTest
public class ApprovalClassTest {
    static testMethod void approvalTest(){
		Quote__c quote = new Quote__c();
		quote.Name = 'Test quote';
		insert quote;

		Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
		app.setObjectId(quote.id);
		Approval.ProcessResult result = Approval.process(app);
        ApprovalProcessController.getQuoteNames(quote.id);    
	}
}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh