You need to sign in to do that
Don't have an account?
RAMANJINEYULU GOGULA
Can anyone help me writing test class for this code
public with sharing class Rfleet_DEListofUnitOrderRPT_TRG {
public static void onAfterUpdate(Map<Id,CST_Carset__c> mcarsets){
string cstRectype=null;
string strCodeconcat1to9=null;
string strCodeconcat10to18=null;
List<CST_Carset__c> lsupdateCarSet=new list<CST_Carset__c>();
for (Rfleet_CountryInfo__c setting : Rfleet_CountryInfo__c.getAll().values()){
if(setting.Name=='DE'){
cstRectype=setting.Rfleet_CST_RecordType__c;
}
}
system.debug('$##'+cstRectype);
Id cstrectyprId = Schema.SObjectType.CST_Carset__c.RecordTypeInfosByName.get(cstRectype).RecordTypeId;
system.debug('$##'+cstrectyprId);
List<CST_Carset__c> listCarSet = new list<CST_Carset__c>([select Id,Optionscodes10_18__c,Optionscodes1_9__c,(select code__c,servicetype__c from services__r) from CST_Carset__c where id =:mcarsets.keySet()]
);
for(CST_Carset__c cstoption:listCarSet){
system.debug('cstoption .services__r.size()>>>'+cstoption.services__r.size());
integer j=0;
integer k=0;
integer count=0;
for(Integer i=0;i<cstoption.services__r.size();i++) {
if(cstoption.services__r[i].servicetype__c=='Option' && count<8) {
if(cstoption.services__r[i].code__c!=null) {
if(j==0){
strCodeconcat1to9=cstoption.services__r[i].code__c+' ';
j++;
}else{
strCodeconcat1to9+=cstoption.services__r[i].code__c+' ';
}
}
count++;
System.debug('if count:::'+count);
}else if(cstoption.services__r[i].servicetype__c=='Option'){
if(cstoption.services__r[i].code__c!=null) {
if(k==0){
strCodeconcat10to18=cstoption.services__r[i].code__c+' ';
k++;
}else{
strCodeconcat10to18+=cstoption.services__r[i].code__c+' ';
}
}
}
cstoption.Optionscodes1_9__c=strCodeconcat1to9;
cstoption.Optionscodes10_18__c=strCodeconcat10to18;
}
System.debug('Codeconcat1to9:::'+strCodeconcat1to9);
System.debug('Codeconcat10to18'+strCodeconcat10to18);
lsupdateCarSet.add(cstoption);
}
try{
update lsupdateCarSet;
}catch(Exception ex) {
system.debug('## Exception occured::'+ ex);
}
}
}
public static void onAfterUpdate(Map<Id,CST_Carset__c> mcarsets){
string cstRectype=null;
string strCodeconcat1to9=null;
string strCodeconcat10to18=null;
List<CST_Carset__c> lsupdateCarSet=new list<CST_Carset__c>();
for (Rfleet_CountryInfo__c setting : Rfleet_CountryInfo__c.getAll().values()){
if(setting.Name=='DE'){
cstRectype=setting.Rfleet_CST_RecordType__c;
}
}
system.debug('$##'+cstRectype);
Id cstrectyprId = Schema.SObjectType.CST_Carset__c.RecordTypeInfosByName.get(cstRectype).RecordTypeId;
system.debug('$##'+cstrectyprId);
List<CST_Carset__c> listCarSet = new list<CST_Carset__c>([select Id,Optionscodes10_18__c,Optionscodes1_9__c,(select code__c,servicetype__c from services__r) from CST_Carset__c where id =:mcarsets.keySet()]
);
for(CST_Carset__c cstoption:listCarSet){
system.debug('cstoption .services__r.size()>>>'+cstoption.services__r.size());
integer j=0;
integer k=0;
integer count=0;
for(Integer i=0;i<cstoption.services__r.size();i++) {
if(cstoption.services__r[i].servicetype__c=='Option' && count<8) {
if(cstoption.services__r[i].code__c!=null) {
if(j==0){
strCodeconcat1to9=cstoption.services__r[i].code__c+' ';
j++;
}else{
strCodeconcat1to9+=cstoption.services__r[i].code__c+' ';
}
}
count++;
System.debug('if count:::'+count);
}else if(cstoption.services__r[i].servicetype__c=='Option'){
if(cstoption.services__r[i].code__c!=null) {
if(k==0){
strCodeconcat10to18=cstoption.services__r[i].code__c+' ';
k++;
}else{
strCodeconcat10to18+=cstoption.services__r[i].code__c+' ';
}
}
}
cstoption.Optionscodes1_9__c=strCodeconcat1to9;
cstoption.Optionscodes10_18__c=strCodeconcat10to18;
}
System.debug('Codeconcat1to9:::'+strCodeconcat1to9);
System.debug('Codeconcat10to18'+strCodeconcat10to18);
lsupdateCarSet.add(cstoption);
}
try{
update lsupdateCarSet;
}catch(Exception ex) {
system.debug('## Exception occured::'+ ex);
}
}
}
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
- http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
I hope it will be helpful.Please mark it as best answer if the information is informative.
Best Regards
Rahul Kumar