I have 3 objects. I am migrating data from one object to two objects. For example I have Account1, Account2, Account3 objects. I am migrating Data from Account1 to Account2 and Account3. Here Account2 is master of Account3. First I am migrating Account1 to Account2. I am storing Account1 ID into customfield called "Account1ReferenceID" in Account2 while migrating. Now I am migrating Account1 to Account3. Here in Account3 I need to map the parent name in Account2. By using "Account1ReferenceID" in Account2. Here is my code for Account1 to Account3. I know using maps I can get it but I am not familiar with maps.
List<Account1__c> acc1=new List<Account1__c>();
acc1=[select ID, Name from Account1__c ];
List<Account2__c> acc2=new List<Account2__c>();
acc2= [Select ID, Name, Account1ReferenceId__c from Account2__c where Accoun1ReferenceId__c!=null];
List<Account3__c> acc3=new List<Account3__c>();
for(Account1__c account1: acc1){
Account3__c account3 = new Account3__c();
account3.Name = acc1.name;
account3.Account2 =
// Account2 is master. How can i find the master in Account2.
acc3.add(account3);
}
try{
insert acc3;
}
catch(Exception e){
System.debug('The following exception has occurred: ' + e.getMessage());
}