You need to sign in to do that
Don't have an account?

MAP using Trigger
Private void UpdatePriceListDate(List<Account> newAccounts){
//Create the instance for the Account
List<Account> ChildRecords = new List<Account>();
//Variable Declaration
string CurrentAccountNotes;
string CurrentParentId;
date PrilistCorrectdate;
for (Account currentrecord : newAccounts) {
//Getting the parentid, PriceListDate and Account notes
CurrentParentId = currentrecord.id;
PrilistCorrectdate = currentrecord.Price_List_Correct__c;
CurrentAccountNotes =currentrecord.Account_Notes__c;
}
ChildRecords = [Select id,Parentid,Price_List_Correct__c,Account_Notes__c, from account where parentid = :CurrentParentId];
for (Account childrecord : ChildRecords) {
//Update the PriceList Date to Childrecord
childrecord.Price_List_Correct__c = PrilistCorrectdate;
//Update the Account Notes to Childrecord
childrecord.Account_Notes__c = CurrentAccountNotes;
}
//Updata the Child Records
update ChildRecords;
}
}
//Create the instance for the Account
List<Account> ChildRecords = new List<Account>();
//Variable Declaration
string CurrentAccountNotes;
string CurrentParentId;
date PrilistCorrectdate;
for (Account currentrecord : newAccounts) {
//Getting the parentid, PriceListDate and Account notes
CurrentParentId = currentrecord.id;
PrilistCorrectdate = currentrecord.Price_List_Correct__c;
CurrentAccountNotes =currentrecord.Account_Notes__c;
}
ChildRecords = [Select id,Parentid,Price_List_Correct__c,Account_Notes__c, from account where parentid = :CurrentParentId];
for (Account childrecord : ChildRecords) {
//Update the PriceList Date to Childrecord
childrecord.Price_List_Correct__c = PrilistCorrectdate;
//Update the Account Notes to Childrecord
childrecord.Account_Notes__c = CurrentAccountNotes;
}
//Updata the Child Records
update ChildRecords;
}
}
You can use Map<Id id, List<Account>> ListOfAccount = new Map<Id id, List<Account>> ([Select id,Parentid,Price_List_Correct__c,Account_Notes__c, from account where parentid = :CurrentParentId]);
Then the result of query automatically store in map . Each record will store corrsponding to id.
All Answers
You can use Map<Id id, List<Account>> ListOfAccount = new Map<Id id, List<Account>> ([Select id,Parentid,Price_List_Correct__c,Account_Notes__c, from account where parentid = :CurrentParentId]);
Then the result of query automatically store in map . Each record will store corrsponding to id.