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
Ammar P 9Ammar P 9 

Pls help me for writing test class.

public class SpecialPricingMassSubmissionForApproval {
    public List<Special_Pricing__c> selLst;
    
    // Constructor
    public SpecialPricingMassSubmissionForApproval(ApexPages.StandardSetController cntlr){
        selLst = cntlr.getSelected();
    }
    
    public pageReference sendForApproval(){
        system.debug('selLst : '+ selLst);
        if(selLst.isEmpty()){
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.Error, 'Please select atleast 1 record for submission!!');
            ApexPages.addMessage(msg);
            return null;
        }
        List<Approval.ProcessSubmitRequest> requests = new List<Approval.ProcessSubmitRequest> ();
        for (Special_Pricing__c spObj: selLst) {
            Approval.ProcessSubmitRequest appReq = new Approval.ProcessSubmitRequest();
            appReq.setComments('Submitting request for approval ');
            appReq.setObjectId(spObj.Id);
            requests.add(appReq);
        }
        
        Approval.ProcessResult[] processResults = null;
        try {
            processResults = Approval.process(requests, true);
            return new ApexPages.Action('{!List}').invoke();
            
        }catch (Exception e) {
            System.debug('Exception Is ' + e.getMessage());
            if(e.getMessage().contains('ALREADY_IN_PROCESS, This record is currently in an approval process')){
                e.setMessage('Approval Process is already in progress!!');
            }
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.Error, e.getMessage());
            ApexPages.addMessage(msg);
            //return null;
        }
        return null;
    }
    
    public pageReference back(){
        return new ApexPages.Action('{!List}').invoke();
    }
}
SwethaSwetha (Salesforce Developers) 
HI Ammar,
The below articles give an idea of how code coverage can be improved. You will need to customize based on your requirement
 
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
 
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
 
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you