You need to sign in to do that
Don't have an account?
SFDC pv
Hi, How to write test class for lightning
Apex class:-
@AuraEnabled
public static String updatecase(String caseId, String accountId, String results)
{
Set<String> loffinstr = new Set<String>();
List<XXX> DFFlist= new list<XXX>([SELECT Number__c FROM XXX WHERE Case__c =:CaseId ]);
for(XXX finfo : DFFlist ){
loffinstr.add(finfo.Number__c);
}
List<XXX> lstpss= new List<XXX>();
List<Object> fieldList = (List<Object>)JSON.deserializeUntyped(results);
System.debug('ffmap'+results);
if(!fieldList.isEmpty()) {
for(Object fld : fieldList){
Map<String,Object> data = (Map<String,Object>)fld;
system.debug(data.get('key1'));
if(!loffinstr.contains(String.valueOf(data.get('key2')))) {
XXX FFrecs = new XXX();
FFrecs.Case__c = caseId;
FFrecs.Account__c = accountId;
FFrecs.Name = String.valueOf(data.get('key0'));
lstpss.add(FFrecs);
}
}
}
insert lstpss;
}
Helper class :-
//call apex class method
var action = component.get('c.updatecase');
//var objList = component.get("v.selectedpss");
var myMap = component.get("v.selectedpss");
console.log('type 2-' + typeof myMap);
console.log('ValuesOfmyMap' +JSON.stringify(myMap));
action.setParams({
"caseId": component.get("v.CaseId"),
"accountId" : component.get("v.AccountId"),
"results" : JSON.stringify(myMap)
});
Especially tell me how to pass the parameter(caseid,accountid,results) which is in Helper to Apex test class
@AuraEnabled
public static String updatecase(String caseId, String accountId, String results)
{
Set<String> loffinstr = new Set<String>();
List<XXX> DFFlist= new list<XXX>([SELECT Number__c FROM XXX WHERE Case__c =:CaseId ]);
for(XXX finfo : DFFlist ){
loffinstr.add(finfo.Number__c);
}
List<XXX> lstpss= new List<XXX>();
List<Object> fieldList = (List<Object>)JSON.deserializeUntyped(results);
System.debug('ffmap'+results);
if(!fieldList.isEmpty()) {
for(Object fld : fieldList){
Map<String,Object> data = (Map<String,Object>)fld;
system.debug(data.get('key1'));
if(!loffinstr.contains(String.valueOf(data.get('key2')))) {
XXX FFrecs = new XXX();
FFrecs.Case__c = caseId;
FFrecs.Account__c = accountId;
FFrecs.Name = String.valueOf(data.get('key0'));
lstpss.add(FFrecs);
}
}
}
insert lstpss;
}
Helper class :-
//call apex class method
var action = component.get('c.updatecase');
//var objList = component.get("v.selectedpss");
var myMap = component.get("v.selectedpss");
console.log('type 2-' + typeof myMap);
console.log('ValuesOfmyMap' +JSON.stringify(myMap));
action.setParams({
"caseId": component.get("v.CaseId"),
"accountId" : component.get("v.AccountId"),
"results" : JSON.stringify(myMap)
});
Especially tell me how to pass the parameter(caseid,accountid,results) which is in Helper to Apex test class
You write test class for your apex controller in the same way you write test class for other apex classes.
First insert records for particular object you are using. Then apply start test and stop test while calling the apex method updatecase. You will be knowing what kind of results you will be getting. Pass the values accordingly while calling the method.
If you have more queries please refer : https://developer.salesforce.com/forums/?id=9060G000000I1OrQAK
Hope this has solved your query, Please mark this as best answer if so.
Regards
Gulafsha