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
RuniRuni 

Test class Aura

Hi team,

How to write test class below calss.

public class InquiryConvertController {
    @AuraEnabled
    public static String getLeadId(String inquiryId){
        Inquiry__c leadId=[select id,Inquiry_Lead__c from Inquiry__c where id=:inquiryId];
        return leadId.Inquiry_Lead__c;
    }
    @AuraEnabled
    public static Id populateOpp(String leadId,String inquiryId) {
        if(leadId !=null){
            Database.update(new Lead(id=leadId,Inquiry__c=inquiryId));
        }
        return leadId;
    }
}
Best Answer chosen by Runi
SwethaSwetha (Salesforce Developers) 
HI Swathi,
Try
@istest
public class InquiryConvertControllerTest {
static testMethod void myUnitTest()  {
    Lead lstLead =   new Lead();
        lstLead.Company = ‘JohnMiller’;
        lstLead.LastName = ‘Mike’;
        lstLead.Status = ‘Open’;
        insert lstLead;
    Inquiry__c inq= new Inquiry__c();
    inq.name=‘sample’;
    inq.Inquiry_Lead__c=lstLead.id;
    insert inq;
    String leadid=InquiryConvertController.getLeadId(inq.id);
    system.assertEquals(lstLead.id, leadid);
    String leadid2=InquiryConvertController.populateOpp(lstLead.id,inq.id );
}
}

If this information helps, please mark the answer as best. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
Hi Swathi,

Can you clarify the relationship between Inquiry__c and the Lead object (which is the child object and which is the parent object)? 

Thanks
RuniRuni
Hi Swetha,

Lead is Parent and Inquiry__c ic child object.

Thanks
Swathi
SwethaSwetha (Salesforce Developers) 
HI Swathi,
Try
@istest
public class InquiryConvertControllerTest {
static testMethod void myUnitTest()  {
    Lead lstLead =   new Lead();
        lstLead.Company = ‘JohnMiller’;
        lstLead.LastName = ‘Mike’;
        lstLead.Status = ‘Open’;
        insert lstLead;
    Inquiry__c inq= new Inquiry__c();
    inq.name=‘sample’;
    inq.Inquiry_Lead__c=lstLead.id;
    insert inq;
    String leadid=InquiryConvertController.getLeadId(inq.id);
    system.assertEquals(lstLead.id, leadid);
    String leadid2=InquiryConvertController.populateOpp(lstLead.id,inq.id );
}
}

If this information helps, please mark the answer as best. Thank you
This was selected as the best answer