+ Start a Discussion
Shubham Sinha 49Shubham Sinha 49 

How to call class from anonymous window

I have a class on which i need to call 'createUserAccount' method but how to set parameter for this method in anonymous window , I do not know please help on this
/**
* @author: Shubham Sinha
* @date: 02/10/2020
* @description: This class is used for creating User Account and User records when a person tries to Login through Janrain
**/

Public Class BIIB_CreateAccountAndUser_Helper{
    /**
* 
* @description: Wrapper class for User and Account Creation, getting wrapper values from BIIB_ADU_Janrain_AuthProviderHandler Class

**/    
    Public class registrationDetails {
        
        public String firstName;
        public String lastName;
        public String fullName;
        public String email;
        public String username;
        public String locale;
        public String provider;
        Public String siteLoginUrl; 
        Public String identifier; 
        Public String link;
        Public Map<String,String> attributeMap;
        
       
    }
    
    /**
* @author: Shubham Sinha
* @description: Creates User Account and Patient therapy record.

**/
    public Static User createUserAccount(registrationDetails regDetailsWrapObj){
        Product_vod__c prodCatlog = [SELECT Name FROM Product_vod__c WHERE Name = :System.label.BIIB_Product_Aducanumab];
        Id recordTypeId = Schema.SObjectType.BIIB_Patient_Therapy__c.getRecordTypeInfosByName().get('BIIB_AD').getRecordTypeId();
        Id recordTypeIdAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('BIIB_Patient').getRecordTypeId();
        
        List<Account> checkAccountData = [SELECT id,FirstName, LastName, PersonEmail,BIIB_PASS_Zip_Code__c FROM Account 
                                          WHERE LastName =: regDetailsWrapObj.LastName AND BIIB_PASS_Zip_Code__c =: regDetailsWrapObj.attributemap.get('ZIP')
                                          AND PersonEmail =: regDetailsWrapObj.Email Limit 1 ];
        Account createAccount;
        if(checkAccountData.size()> 0)
        {
            createAccount = checkAccountData[0];
            BIIB_Patient_Therapy__c patTherapy = new BIIB_Patient_Therapy__c();
            patTherapy.RecordTypeId = recordTypeId;
            patTherapy.BIIB_Indication__c = System.label.BIIB_Patient_Therapy_Indication;
            patTherapy.BIIB_Therapy__c = prodCatlog.Name;
            patTherapy.BIIB_Patient__c= createAccount.id;
            
            insert patTherapy;
        }
        else 
        {
           
            createAccount = new Account ();
            createAccount.FirstName= regDetailsWrapObj.firstName;
            createAccount.LastName =regDetailsWrapObj.lastName;
            createAccount.RecordTypeId = recordTypeIdAccount;
            insert createAccount;
 
          BIIB_Patient_Therapy__c accPatTherapy = new BIIB_Patient_Therapy__c();
            accPatTherapy.BIIB_Indication__c = System.label.BIIB_Patient_Therapy_Indication;
            accPatTherapy.BIIB_Therapy__c = prodCatlog.Name;
            accPatTherapy.BIIB_Patient__c= createAccount.id;
            insert accPatTherapy;

            
        }
        User aduUser = createAduCommunityUser(regDetailsWrapObj, createAccount.id);
        return aduUser;
    }
    
    public Static User createAduCommunityUser(registrationDetails regDetailsWrapObj, Id accountId){
        //create community user with related account id
        User aduUser = new User();
        aduUser.contactId = accountId;
        return aduUser;
    }
    
}
Best Answer chosen by Shubham Sinha 49
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi shubam,

createUserAccount has wrapper class as parameter.So we have to create a variable of type wrapperclass first and then invoke this method.But I think we cannot create a wrapper class variable because there is no constructor written in registrationDetails wrapper class.
Below code will work if your wrapper class has contructor. 
BIIB_CreateAccountAndUser_Helper.registrationDetails dtls  = new BIIB_CreateAccountAndUser_Helper.registrationDetails();
//give values to all the variable of wrapper class
dtsl.firstName =  '';
dtsl.firstName =  '';
........

BIIB_CreateAccountAndUser_Helper BCH = new BIIB_CreateAccountAndUser_Helper();
BCH.createUserAccount(dtls);


Please refer below link which might help you in this
https://salesforce.stackexchange.com/questions/187546/not-able-to-cover-wrapper-class-in-test-class/187547

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards