+ Start a Discussion
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12 

MAP using Trigger

Hi Guys,

Any body have using MAP Please find the code, How this code change to MAP?

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;
    }
}


Thanks...
Best Answer chosen by sundhar.mks1.3962649227519546E12
Ravikant kediaRavikant kedia
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

Ravikant kediaRavikant kedia
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
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi Ravikant,

How to change this code to bulk contest? for exmple: at the same time i want to update the >1000 record's, give any idea

Thank's....