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
Deja BondDeja Bond 

Sobject creation

Hi, I need help converting this method into an sobject, so it can accept two different types of objects

So currently the method is returning a lead activity record, but I want it to return a candidate record if the object is a contact, so I was thinking to add another condition to return something like return new LightningActivity(candidateRecord) if this isn't a RH_Lead__c object
public static LightningActivity fetchTestActivity(RH_Lead__c leadRecord) {
        if(leadRecord == null){
            system.debug('got a null');
            return fetchTestActivity();
        }
        return new LightningActivity(leadRecord);
    }
Raj VakatiRaj Vakati
try this
 
public static LightningActivity fetchTestActivity(Sobject leadRecord) {
        if(leadRecord == null && leadRecord.getSObjectType=='Lead'){
            system.debug('got a null');
            return fetchTestActivity();
        }else{
        return new LightningActivity(leadRecord);
		}
    }

 
Deja BondDeja Bond
Thanks for the logic, but I am also trying to see if the record is of type Contact,
So do you think this would work?
Do I need to return(candidateRecord ) somewhere ?
 public static LightningActivity fetchTestActivity(sobject leadRecord) {
        if(leadRecord == null && leadRecord.getSObjectType=='RH_Lead__c')
        {
            system.debug('got a null');
            return fetchTestActivity();
        }
        if(candidateRecord == null && candidateRecord getSObjectType=='Contact')
        {
            system.debug('got a null');
            return fetchTestActivity();
        }
        else{
        return new LightningActivity(leadRecord);
        }
    }
Deja BondDeja Bond
forgot to put the sobject candidateRecord as a parameter
Raj VakatiRaj Vakati
it works ..
Deja BondDeja Bond
No with this code, it is not, I am getting that
"Constructor not defined: [LightningActivity].<Constructor>(SObject)"
"Variable does not exist: getSObjectType"



    @AuraEnabled
    public static LightningActivity fetchTestActivity(sobject leadRecord, sobject candidateRecord) {
        if(leadRecord == null && leadRecord.getSObjectType=='RH_Lead__c')
        {
            system.debug('got a null');
            return fetchTestActivity();
        }
        if(candidateRecord == null && candidateRecord.getSObjectType=='Contact')
        {
            system.debug('got a null');
            return fetchTestActivity();
        }
        else{
        return new LightningActivity(leadRecord);
        }
    }


Am I missing something?