+ Start a Discussion
mahesh p 54mahesh p 54 

i have a method UpdateAccounts(Set<Id> accIdSet):how do i get all the accounts whose id is passed in the Set and if the name of the account contains test add a description to account "This is test account"

how to pass the id and add it to the Set
Best Answer chosen by mahesh p 54
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi mahesh,

Try this code:
 
List<Account> accUpdateList=new List<Account>();
List<Account> accList=new List<Account>([select id,name,description from Account where id in: accIdSet]);
for(Account acc:accList)
{
if(acc.name.contains('test'))
{
acc.description='This is test account';
accUpdateList.add(acc);
}
}
update accUpdateList;

 

All Answers

Bhargavi TunuguntlaBhargavi Tunuguntla
Hi mahesh,

Try this code:
 
List<Account> accUpdateList=new List<Account>();
List<Account> accList=new List<Account>([select id,name,description from Account where id in: accIdSet]);
for(Account acc:accList)
{
if(acc.name.contains('test'))
{
acc.description='This is test account';
accUpdateList.add(acc);
}
}
update accUpdateList;

 
This was selected as the best answer
v varaprasadv varaprasad
Hi Mahesh,

Try This : 
List<Account> accUpdateList=new List<Account>();

list<account> aaList = [select id,name,description from account where name like '%test%' and id in : accIdSet];

for(account acc : aaList){
   acc.description = 'This is test account';
   accUpdateList.add(acc);
}

if(accUpdateList != null){
  update accUpdateList;
}

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/

Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1