You need to sign in to do that
Don't have an account?
SFDC demo
Unit Test class for Custom Metadata.
Hi All,
I have created a parent-child relationship on two custom metadata in my case, My apex trigger is not covering because of custom metadata, but I couldn't access parent records to a child in a test class. Please help me with this.
here below my code.
I am invoking the test data from test class to set custom metadata in triggerHander
//Main class if(test.isrunningtest()){
list<DuplicateUpdateRules__mdt> duplicateUpdateRulesList=new list<DuplicateUpdateRules__mdt>();
duplicateUpdateRulesList=DuplicateManagementHelperTestBulk.getDuplicateUpdateRu();//Get testdata to cover
}
Test class
//set testData DuplicateKeys
public DuplicateKeys__mdt getDuplicateKeys() { //Parent
DuplicateKeys__mdt objDuplicatekey=new DuplicateKeys__mdt();
objDuplicatekey.DeveloperName ='AR_DupKey1_Seq1';
objDuplicatekey.Country__c='AR';
objDuplicatekey.FieldAPIName__c='DupMatchkey1__c';
objDuplicatekey.ObjectAIPName__c='Account';
objDuplicatekey.Id='m0j9E0000004Ck4QAE';
return objDuplicatekey;
}
//Child custom metadata.
public List<DuplicateUpdateRules__mdt> getDuplicateUpdateRu(){
list<DuplicateKeys__mdt> objDuplicatekeylists = [SELECT id,DeveloperName, Country__c, FieldAPIName__c, ObjectAIPName__c FROM DuplicateKeys__mdt where DeveloperName ='AR_DupKey1_Seq1'];
system.debug('objDuplicatekeylists--->'+objDuplicatekeylists);
/*List<DuplicateUpdateRules__mdt > duplicateRuleList = new List<DuplicateUpdateRules__mdt>();
DuplicateUpdateRules__mdt dup1=new DuplicateUpdateRules__mdt(
DeveloperName= 'ARTest1',
FieldAPIName__c ='BillingStreet',
DuplicateKeys__c=objDuplicatekeylists[0].id,
Sequence__c=1
);
}
I have created a parent-child relationship on two custom metadata in my case, My apex trigger is not covering because of custom metadata, but I couldn't access parent records to a child in a test class. Please help me with this.
here below my code.
I am invoking the test data from test class to set custom metadata in triggerHander
//Main class if(test.isrunningtest()){
list<DuplicateUpdateRules__mdt> duplicateUpdateRulesList=new list<DuplicateUpdateRules__mdt>();
duplicateUpdateRulesList=DuplicateManagementHelperTestBulk.getDuplicateUpdateRu();//Get testdata to cover
}
Test class
//set testData DuplicateKeys
public DuplicateKeys__mdt getDuplicateKeys() { //Parent
DuplicateKeys__mdt objDuplicatekey=new DuplicateKeys__mdt();
objDuplicatekey.DeveloperName ='AR_DupKey1_Seq1';
objDuplicatekey.Country__c='AR';
objDuplicatekey.FieldAPIName__c='DupMatchkey1__c';
objDuplicatekey.ObjectAIPName__c='Account';
objDuplicatekey.Id='m0j9E0000004Ck4QAE';
return objDuplicatekey;
}
//Child custom metadata.
public List<DuplicateUpdateRules__mdt> getDuplicateUpdateRu(){
list<DuplicateKeys__mdt> objDuplicatekeylists = [SELECT id,DeveloperName, Country__c, FieldAPIName__c, ObjectAIPName__c FROM DuplicateKeys__mdt where DeveloperName ='AR_DupKey1_Seq1'];
system.debug('objDuplicatekeylists--->'+objDuplicatekeylists);
/*List<DuplicateUpdateRules__mdt > duplicateRuleList = new List<DuplicateUpdateRules__mdt>();
DuplicateUpdateRules__mdt dup1=new DuplicateUpdateRules__mdt(
DeveloperName= 'ARTest1',
FieldAPIName__c ='BillingStreet',
DuplicateKeys__c=objDuplicatekeylists[0].id,
Sequence__c=1
);
}