You need to sign in to do that
Don't have an account?
nihar
Any one can write a test class for my trigger
trigger TLClusterUpdate on Account (before insert, before update) {
set<Id> tseIds = new Set<Id>();
set<Id> tlIds = new set<Id>();
list<TSE_Master__c> updateTseMasters = new list<TSE_Master__c>();
list<Outlets_Groups_Primary_Customer__c> groupOutlets = new
list<Outlets_Groups_Primary_Customer__c>();
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){
for(Account a : Trigger.new){
if(a.TSE_Code__c != NULL) tseIds.add(a.TSE_Code__c);
if(a.Group_Name1__c!= NULL) tlIds.add(a.Group_Name1__c);
}
updateTseMasters = [SELECT Id, Name, TL_Code__c,TL_Code__r.cluster__c from
TSE_Master__c where Id IN: TseIds];
groupOutlets = [Select Id, Name,Lead_TL__c from
Outlets_Groups_Primary_Customer__c where Id IN: tlIds];
for(Account acc: Trigger.New){
for(TSE_Master__c ts: updateTseMasters){
acc.TL_Code__c = ts.TL_Code__c;
acc.Cluster_Code__c = ts.TL_Code__r.Cluster__c;
}
for(Outlets_Groups_Primary_Customer__c grps: groupOutlets){
acc.Group_Lead_TL__c = grps.Lead_TL__c;
}
}
}
}
set<Id> tseIds = new Set<Id>();
set<Id> tlIds = new set<Id>();
list<TSE_Master__c> updateTseMasters = new list<TSE_Master__c>();
list<Outlets_Groups_Primary_Customer__c> groupOutlets = new
list<Outlets_Groups_Primary_Customer__c>();
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){
for(Account a : Trigger.new){
if(a.TSE_Code__c != NULL) tseIds.add(a.TSE_Code__c);
if(a.Group_Name1__c!= NULL) tlIds.add(a.Group_Name1__c);
}
updateTseMasters = [SELECT Id, Name, TL_Code__c,TL_Code__r.cluster__c from
TSE_Master__c where Id IN: TseIds];
groupOutlets = [Select Id, Name,Lead_TL__c from
Outlets_Groups_Primary_Customer__c where Id IN: tlIds];
for(Account acc: Trigger.New){
for(TSE_Master__c ts: updateTseMasters){
acc.TL_Code__c = ts.TL_Code__c;
acc.Cluster_Code__c = ts.TL_Code__r.Cluster__c;
}
for(Outlets_Groups_Primary_Customer__c grps: groupOutlets){
acc.Group_Lead_TL__c = grps.Lead_TL__c;
}
}
}
}
Please try below code for test class. Please let me know if you are facing any issue.
Thanks
Hemant
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
You write a test class for this the same way that you would any other:
- Set up some data for the Trigger to access
- Verify the behaviour with asserts.
Try below sample test class.
Please try below test class
Let us know if this will help u