function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pooja chauchanpooja chauchan 

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;
    }
}
Best Answer chosen by pooja chauchan
Gaurav NirwalGaurav Nirwal

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

bob_buzzardbob_buzzard
Is there a question here?  
Gaurav NirwalGaurav Nirwal

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.
This was selected as the best answer