Skip to main content
kishore koni ha fatto una domanda in #Customer Service
set<id> set1=new set<id>();

 

list<contact>conlist=[select id,name from contact where name='Ashok143'];

 

for(contact con:conlist)

 

{

 

   set1.add(con.accountid);

 

}

 

list<account> acclist=[select id,name from account where id in:set1];

 

for(account acc:acclist)

 

{

 

   acc.name='ram';

 

   update acc;

 

  system.debug('account  record is'+acc);

 

}

 

//accountname=ashok143

 

let change the account name as  Ram

 

I am getting error null why 
2 risposte
  1. 4 giu 2014, 11:18
    kishore,

     

    you shouldn't be doing DML inside loops.. give this a try and see if it works..

     

    set<id> set1=new set<id>();

    list<Contact> conlist= [select id,accountid,Name from Contact where name='Ashok143'];

    if(conlist.size() > 0){

    for(Contact con:conlist)

    {

    set1.add(con.accountid);

    }

    list<Account> acclist= [select id,name from Account where id in:set1];

    if(acclist.size() > 0){

    for(account acc:acclist)

    {

    acc.name='ram';

    }

    update acclist;

    }

    }

0/9000