Main class example
public without
sharing class MyOrderHistoryController {
@TestVisible private static
list<SoldToSet__x> mockedcustlist = new List<SoldToSet__x>();
@AuraEnabled
//filter values for the report based on
logged in customer
public static list<SoldSet__x>
getCustomers( string soldtono){
list<SoldSet__x> custlist=new
list<SoldSet__x>();
//query Sold To account details
if(!Test.isRunningTest()){
for(SoldSet__x
oh: [SELECT Flag__c,City__c,Name__c,SoldToNr__c FROM SoldSet__x WHERE SoldToNr__c IN:soldtono]){
custlist.add(oh);
}
}else{
custlist.addAll(mockedcustlist);
}
return custlist;
}
Test class
@isTest
public without
sharing class MyOrderHistoryControllertest {
static testMethod void myTest() {
SoldSet__x mockedCust1 = new
SoldSet__x(
SoldToNr__c='600459',
Name__c='abcLtd',
City__c='test1',
Flag__c='YES'
);
SoldSet__x
mockedCust2 = new SoldSet__x(
SoldToNr__c='600459',
Name__c='xyzLtd',
City__c='test2',
Flag__c='NO'
);
MyOrderHistoryController.mockedcustlist.add(mockedCust1);
MyOrderHistoryController.mockedcustlist.add(mockedCust2);
//run as portal user
system.runas(u){
list<SoldSet__x>
accs=new list<SoldSet__x>();
accs
= MyOrderHistoryController.getCustomers();
System.assert(accs
!= null);
}
}
}
Hi Gautham,
ReplyDeleteI really need of your help.I wanted to impliment the same and when in try your logic its not covering my code coverage for external objects.
Please let me know if i get some help from you?
It is saying fields not writable (External object fields are not writable)
ReplyDeleteits not writable, do we have alternate option ? thanks
ReplyDelete