You need to sign in to do that
Don't have an account?
t j 5
stuck in test case for duplicate rule
Hi,
please provide test case for class which having duplicate rule.
global class CopyAcc implements Database.Batchable<sObject> {
Set<Id> setDuplicateIds = new Set<id>();
global Database.QueryLocator start(Database.BatchableContext bc)
{
String query= 'select id,name,website,billingcity,phone,billingstreet from account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<Account> scope)
{
system.debug('account '+scope);
for(Account a : scope)
{
Database.SaveResult sr = Database.insert(account, false);
if (!sr.isSuccess()) {
Datacloud.DuplicateResult duplicateResult;
// Insertion failed due to duplicate detected
for(Database.Error duplicateError : sr.getErrors()){
duplicateResult = ((Database.DuplicateError)duplicateError).getDuplicateResult();
}
// Fetch the Ids of the existing duplicate records
for(Datacloud.MatchResult duplicateMatchResult : duplicateResult.getMatchResults()) {
for(Datacloud.MatchRecord duplicateMatchRecord : duplicateMatchResult.getMatchRecords()) {
customobj_c ob = new customobj_c (name_c=a.name);
insert ob;
}
}
// System.debug('Duplicate records ' + setDuplicateIds);
}
else
{
}
}
}
global void finish(Database.BatchableContext bc)
{
}
}
Thanks
please provide test case for class which having duplicate rule.
global class CopyAcc implements Database.Batchable<sObject> {
Set<Id> setDuplicateIds = new Set<id>();
global Database.QueryLocator start(Database.BatchableContext bc)
{
String query= 'select id,name,website,billingcity,phone,billingstreet from account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<Account> scope)
{
system.debug('account '+scope);
for(Account a : scope)
{
Database.SaveResult sr = Database.insert(account, false);
if (!sr.isSuccess()) {
Datacloud.DuplicateResult duplicateResult;
// Insertion failed due to duplicate detected
for(Database.Error duplicateError : sr.getErrors()){
duplicateResult = ((Database.DuplicateError)duplicateError).getDuplicateResult();
}
// Fetch the Ids of the existing duplicate records
for(Datacloud.MatchResult duplicateMatchResult : duplicateResult.getMatchResults()) {
for(Datacloud.MatchRecord duplicateMatchRecord : duplicateMatchResult.getMatchRecords()) {
customobj_c ob = new customobj_c (name_c=a.name);
insert ob;
}
}
// System.debug('Duplicate records ' + setDuplicateIds);
}
else
{
}
}
}
global void finish(Database.BatchableContext bc)
{
}
}
Thanks
1) http://amitsalesforce.blogspot.com/search/label/Batch%20Job Let us know if this will help you