You need to sign in to do that
Don't have an account?
sumit d
batch to create junction object for duplicate Account records
Hi All,
i have requirement in which i have a juction object called family__c. i have two lookup Sister_Company__c and Sister_Company2__c. i am creating a batch in which i want to create records of Accounts having duplicate names.and both duplicates will go in Sister_Company__c and Sister_Company2__c lookup fields.
example like Account 'ABC' with record type 'A'. and have 2 more account with same name as 'ABC' having record type 'B',and record type 'C'. than junction object records should created and the fill the fields like:- Sister_Company__c = 'ABC(A)' and Sister_Company2__c = 'ABC(B)'. and 2nd record as:-Sister_Company__c = 'ABC(A)' and Sister_Company2__c = 'ABC(c)' creating two junction records like this for ABC(A).
i am trying to create a batch given below. but not able to take Account which have duplicate name in query .
how will i insert the duplicate Account name in Sister_Company2__c.
how to do this ?
Any suggestions?
My batch is given below:-
public class BatchFBGFamilies implements Database.Batchable<sObject> {
public static void run( Set<Id> AccIds ) {
List<Account> accountRecords = [Select id, RecordTypeId, RecordType.Name,Name
From Account
Where Id IN: AccIds ];
executeHelper( accountRecords );
}
public Database.QueryLocator start(Database.BatchableContext BC){
String query = 'Select id, RecordTypeId, RecordType.Name, Name, ' +
'RecordType.developerName' +
'FROM Account' ;
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<Account> scope){
executeHelper( scope );
}
public void finish(Database.BatchableContext BC){
}
public static void executeHelper( List<Account> scope ) {
List<FBG_Family__c> ListFBGFamily = new List<FBG_Family__c>();
for (Account acc : scope)
{
FBG_Family__c Family = new FBG_Family__c();
Family.Sister_Company__c = acc.id;
Family.Sister_Company2__c = acc.id;
ListFBGFamily.add(Family);
}
Insert ListFBGFamily;
}
}
i have requirement in which i have a juction object called family__c. i have two lookup Sister_Company__c and Sister_Company2__c. i am creating a batch in which i want to create records of Accounts having duplicate names.and both duplicates will go in Sister_Company__c and Sister_Company2__c lookup fields.
example like Account 'ABC' with record type 'A'. and have 2 more account with same name as 'ABC' having record type 'B',and record type 'C'. than junction object records should created and the fill the fields like:- Sister_Company__c = 'ABC(A)' and Sister_Company2__c = 'ABC(B)'. and 2nd record as:-Sister_Company__c = 'ABC(A)' and Sister_Company2__c = 'ABC(c)' creating two junction records like this for ABC(A).
i am trying to create a batch given below. but not able to take Account which have duplicate name in query .
how will i insert the duplicate Account name in Sister_Company2__c.
how to do this ?
Any suggestions?
My batch is given below:-
public class BatchFBGFamilies implements Database.Batchable<sObject> {
public static void run( Set<Id> AccIds ) {
List<Account> accountRecords = [Select id, RecordTypeId, RecordType.Name,Name
From Account
Where Id IN: AccIds ];
executeHelper( accountRecords );
}
public Database.QueryLocator start(Database.BatchableContext BC){
String query = 'Select id, RecordTypeId, RecordType.Name, Name, ' +
'RecordType.developerName' +
'FROM Account' ;
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<Account> scope){
executeHelper( scope );
}
public void finish(Database.BatchableContext BC){
}
public static void executeHelper( List<Account> scope ) {
List<FBG_Family__c> ListFBGFamily = new List<FBG_Family__c>();
for (Account acc : scope)
{
FBG_Family__c Family = new FBG_Family__c();
Family.Sister_Company__c = acc.id;
Family.Sister_Company2__c = acc.id;
ListFBGFamily.add(Family);
}
Insert ListFBGFamily;
}
}