You need to sign in to do that
Don't have an account?
TempleHoff
How do you generate test data for a trigger that includes D&B Company records?
I've writen a trigger so that when I import an Account record from Data.com or clean one the trigger will use the Parent DUNS on the associated D&B Company record to see if I already have the parent in my org. If I do, then it sets the parent automatically. The trigger works great and is bulkified. But now I'm stuck. How do I generate mock D&B Company records in a Test Method to test against? Do I have to 'see all data' in the TestMethod test from a known real D&B Company record?
All Answers
I'm not a developer (and we don't have a SF developer). Are you willing to share the code for the trigger and test class you wrote?
trigger AccountMain on Account (before insert, before update, after insert, after update) {
//Set Parent based on D&B Record
if((trigger.isInsert || trigger.isUpdate) && trigger.isBefore){
Map<String,string> ParentDUN_Acc_Map = new Map<String,string>{};
List<String> ParentDUN_List = new List<String>();
//cycle through new or updated accounts accounts, determine candidates, record their ParentDUN to the list and them to the ParentDUN to Acc ID Map
for(Account Acc : trigger.new)
{
if(Acc.D_B_Parent_DUNS__c != null && Acc.D_B_Parent_DUNS__c != Acc.DunsNumber && Acc.Parent == null) {
ParentDUN_List.Add(Acc.D_B_Parent_DUNS__c);
string myid = Acc.id;
ParentDUN_Acc_Map.put(Acc.D_B_Parent_DUNS__c, myid);
}
}
//Find all the accounts to be used as parents
List<Account> AccList = [Select DunsNumber, Id From Account where DunsNumber In : ParentDUN_List];
//Create a map of parents to be used
Map<String, String> ParentFoundDUN_ID_Map = new Map<String, String>{};
for(Account Accs : AccList )
{
ParentFoundDUN_ID_Map.put(Accs.DunsNumber, Accs.id);
}
// cycle through the new list and make any parent inserts needed
for(Account AccU : trigger.new)
{
String Uparent = ParentFoundDUN_ID_Map.get(accU.D_B_Parent_DUNS__c);
if(uParent != null) {AccU.parentid = Uparent;}
}
}
}