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
Ravichandra yerubandiRavichandra yerubandi 

how pass data to @aura enabled method from test class

Hi,
i am writing test class to lightning apex controller  i am passing values to parameter of @auraenabled method . i getting null pointer exception because in that method on string varible are written how to pass the values to @auraenabled method varibles from test class
can any one help?
Best Answer chosen by Ravichandra yerubandi
AnudeepAnudeep (Salesforce Developers) 
The below sample code shows how to pass a string variable to AuraEnabled method from test class
 
@AuraEnabled
    public static id Savesupportform(Case casedata, String fileName, String base64Data, String contentType){

    //apex code
    
    }
 
Case cs  = new Case();
cs.Status = 'open';
cs.Helpdesk_Case_Resolution__c = 'Test 123';
cs.Helpdesk_Case_Status__c = 'Closed';
cs.Incident_Owner__c = 'Naveen';
cs.Incident_Number__c  = '12345';

Instantiate the ctssupportform class.

ctssupportform ct = new ctssupportform();
ct.Savesupportform(cs, filename, fileEncoded, type);

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep

All Answers

AnudeepAnudeep (Salesforce Developers) 
The below sample code shows how to pass a string variable to AuraEnabled method from test class
 
@AuraEnabled
    public static id Savesupportform(Case casedata, String fileName, String base64Data, String contentType){

    //apex code
    
    }
 
Case cs  = new Case();
cs.Status = 'open';
cs.Helpdesk_Case_Resolution__c = 'Test 123';
cs.Helpdesk_Case_Status__c = 'Closed';
cs.Incident_Owner__c = 'Naveen';
cs.Incident_Number__c  = '12345';

Instantiate the ctssupportform class.

ctssupportform ct = new ctssupportform();
ct.Savesupportform(cs, filename, fileEncoded, type);

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep
This was selected as the best answer
Ravichandra yerubandiRavichandra yerubandi
Hir Anudeep, thank you for your response
@AuraEnabled
public static id Savesupportform(Case casedata, String fileName, String base64Data, String contentType)
{
String NameVarible=username__c.Name;
}
In the above code how pass value to 'NameVarible' from test class.