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
Shubham Sinha 49Shubham Sinha 49 

Calling method of different class from another method of class

I am callling one method of different class from another merhod of different class, called method searches for record  and if not found it will create a record.(both methods are highlighted in bold).

I want if the search method (searches the record in MDM- third party) returns any record then only the create  method (addAccFromGaine) will execute.
Plesae help
/**
* @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;
        
        Public RegistrationDetails(){
            this.firstName ='';
            this.lastName ='';
            this.fullName = '';
            this.email= '';
            this.username = '';
            this.locale = '';
            this.provider ='';
            this.siteLoginUrl= '';
            this.identifier ='';
            this.link = '';
            
        }
    }
    /**
* @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][0];
        Id recordTypeId = Schema.SObjectType.BIIB_Patient_Therapy__c.getRecordTypeInfosByName().get('Aducanumab').getRecordTypeId();
        Id recordTypeIdAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Patient').getRecordTypeId();
        
        List<Account> checkAccountData = [SELECT id,FirstName, LastName, PersonEmail,BIIB_PASS_Zip_Code__c FROM Account 
                                          WHERE LastName =: regDetailsWrapObj.LastName AND FirstName =:regDetailsWrapObj.FirstName
                                          
                                           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.id;
            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.id;
            accPatTherapy.BIIB_Patient__c= createAccount.id;
            insert accPatTherapy;
            
            String searchTermFirst = regDetailsWrapObj.firstname;
            String searchTermLast = regDetailsWrapObj.Lastname;
            String email = regDetailsWrapObj.email;
            
         // Calling the method from SearchPatientController to search the record in MDM

            ApexPages.StandardController accStdControllerObj = new ApexPages.StandardController(new Account());
            SearchPatientController tc = new SearchPatientController(accStdControllerObj);
            tc.getMDMSearchResult( searchTermFirst, searchTermLast, null,null,email,null,null,null,null,null,null,null,null,null); 
          // this method creates the record.
           ApexPages.StandardController accStdControllerOb = new ApexPages.StandardController(new Account());
              SearchPatientController add = new SearchPatientController(accStdControllerOb);
             add.addAccFromGaine(); 
                   }
     
        User aduUser = createAduCommunityUser(regDetailsWrapObj, createAccount.id);
        return aduUser;
    }
}

 
Suraj MakandarSuraj Makandar
Hi Shubham,

In "getMDMSearchResult" method make sure you return a record or a true/false flag.

Now before calling "addAccFromGaine" method add a IF condition to check the value returned by previous "getMDMSearchResult" method, please refer below code:
 SearchPatientController tc = new SearchPatientController(accStdControllerObj); 

Boolean recordCreated = tc.getMDMSearchResult( searchTermFirst, searchTermLast, null,null,email,null,null,null,null,null,null,null,null,null); 
// this method creates the record. 

if(recordCreated){
ApexPages.StandardController accStdControllerOb = new ApexPages.StandardController(new Account()); 
SearchPatientController add = new SearchPatientController(accStdControllerOb); add.addAccFromGaine(); 
}

Thanks,
​​​​​​​Suraj
Shubham Sinha 49Shubham Sinha 49
Thanks Suraj for the help but I am getting an error "Illegal assignment from List<SearchPatientController.GaineAcc> to Boolean" when used the above approach.
Suraj MakandarSuraj Makandar
Hi Shubham,

What is the return time of "getMDMSearchResult" method?

As I mentioned before, it should be either a record or boolean, I have shared a above code for your reference considering its return type is boolean.

Thanks,
Suraj