You need to sign in to do that
Don't have an account?
sree prasad
Hi Guys could you please give quick response for this Test Class,I need very urgent
I need Test Class for this Trigger
trigger AOS_Case_Creation on Payment_Schedule__c (After Update) {
List<Case> listC = new List<case>();
Set<Id> regId=new Set<Id>();
List<Case> Existingcase = new List<case>();
Map<String,opportunity> mapReg=new Map<String,opportunity>();
for(Payment_Schedule__c updatep:trigger.new){
regId.add(updatep.opportunity__c);
if(regId.size()>0){
mapReg=new Map<String,opportunity>([SELECT Id,Name,AccountId,Account.PersonContactId FROM Opportunity]);
}
if(updatep.Display_Order__c == 1.0 && updatep.Status__c == 'Completed'){
Existingcase =[select Subject,Type from case where Opportunity__c=:updatep.Opportunity__c and Subject='Agreement for Sale'];
if(Existingcase.size()==0){
Case Cs= new Case();
cs.Payment_Schedule__c=updatep.id;
cs.ownerid=updatep.id;
Cs.Subject='Agreement for Sale';
Cs.Type='Agreement for Sale';
cs.Opportunity__c=updatep.Opportunity__c;
system.debug('================== cs.Opportunity__c ===================='+cs.Opportunity__c);
cs.AccountId=mapReg.get(updatep.Opportunity__c).AccountId;
system.debug('============================cs.AccountId======================='+cs.AccountId);
cs.ContactId=mapReg.get(updatep.Opportunity__c).Account.PersonContactId ;
listC .add(Cs);
}
}
}
Insert listC;
}
trigger AOS_Case_Creation on Payment_Schedule__c (After Update) {
List<Case> listC = new List<case>();
Set<Id> regId=new Set<Id>();
List<Case> Existingcase = new List<case>();
Map<String,opportunity> mapReg=new Map<String,opportunity>();
for(Payment_Schedule__c updatep:trigger.new){
regId.add(updatep.opportunity__c);
if(regId.size()>0){
mapReg=new Map<String,opportunity>([SELECT Id,Name,AccountId,Account.PersonContactId FROM Opportunity]);
}
if(updatep.Display_Order__c == 1.0 && updatep.Status__c == 'Completed'){
Existingcase =[select Subject,Type from case where Opportunity__c=:updatep.Opportunity__c and Subject='Agreement for Sale'];
if(Existingcase.size()==0){
Case Cs= new Case();
cs.Payment_Schedule__c=updatep.id;
cs.ownerid=updatep.id;
Cs.Subject='Agreement for Sale';
Cs.Type='Agreement for Sale';
cs.Opportunity__c=updatep.Opportunity__c;
system.debug('================== cs.Opportunity__c ===================='+cs.Opportunity__c);
cs.AccountId=mapReg.get(updatep.Opportunity__c).AccountId;
system.debug('============================cs.AccountId======================='+cs.AccountId);
cs.ContactId=mapReg.get(updatep.Opportunity__c).Account.PersonContactId ;
listC .add(Cs);
}
}
}
Insert listC;
}
I don't know what exactly do you need. But, my opinion from this Trigger is not following best practices because it has a SELECT statement inside a loop (FOR). For each opportunity there are consulting for existing cases. My suggestion is, you should use collections, for this case MAP or SET, to search for cases in a massive way. And another this, you should use filters to prevent some limit error. Please, let me know if this is helpful for you.
Thank you.