Ajax (1) Apex Class (12) Apex Trigger (2) Community (2) Home Page (1) HTML (4) Integration (3) JS (7) KB (1) Label (1) Licenses (1) Listing (1) Log (1) OOPs (5) Sharing (1) Static Resource (1) Test Class (3) URI (1) Visualforce (10)

Tuesday, 6 May 2014

An important Case

updating data of one list by getting value from another list we will need a map for this case(2nd ''for loop'')
public void test(list<Contact> triggerNew)
    {
    Set<ID> stID=new Set<ID>();
    if(triggerNew.size()>0 && triggerNew!=null)
    {
    for(Contact obj:triggerNew)
    {
      stID.add(obj.accountid);
    }
    }
    List<Account> lstAccount=new List<Account>();
    Map<id,String> mp=new Map<id,string>();
    lstAccount=[Select id,name from Account where id in:stID];
   for(Account ob:lstAccount)
   {
       mp.put(ob.id,ob.name);
       
   }
    for(Contact objj:TriggerNew)
    {
          objj.Title=mp.get(objj.accountid)+'Krrish';
    }
   
    }
    






No comments:

Post a Comment