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
himanshu huske 7himanshu huske 7 

Need Test Class for controller

public class CSI_DeligationController {

    public static CSI_Response deligateUSer(String deligateeJson){
        if(String.isNotBlank(deligateeJson)){
            CSI_DataWrapper.DeligateeContact contactWrapper =(CSI_DataWrapper.DeligateeContact) JSON.deserialize(deligateeJson, CSI_DataWrapper.DeligateeContact.Class);
             
            if(contactWrapper != null){
                Contact contactRecord = new Contact();
                contactRecord.FirstName = contactWrapper.firstName;
                contactRecord.LastName = contactWrapper.lastName;
                contactRecord.Email = contactWrapper.email;
                contactRecord.AccountId = contactWrapper.accountId;
                
                RecordType recType = [SELECT Id, Name, DeveloperName 
                                      FROM RecordType 
                                      WHERE SObjectType = 'Contact' AND 
                                      		Name =: contactWrapper.recordType ];

                contactRecord.RecordTypeId = recType.id;
                
                try{
                    insert contactRecord;
                    //return CSI_Utils.createPortalUser(contactRecord);
                }catch(Exception ex){
                    System.debug('Exception '+ ex.getMessage());
                    return new CSI_Response(false, ex.getMessage(), '');
                }
            }
        }
        return new CSI_Response(false, '' , '');
    }
}

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Himanshu,

Greetings!

You need to check which lines are covered and which are not to change the code according to the code.

I would suggest you follow the best practices which are listed in the below article:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm

Please mark it as the best answer if it helps you to fix the issue.

Thank you!