Activity › Forums › Salesforce® Discussions › how we can edit the description of account through Salesforce Apex code?
-
how we can edit the description of account through Salesforce Apex code?
Posted by Shubham on July 31, 2017 at 11:20 AMI want to edit randomly selected account from our list of account?
shariq replied 7 years, 8 months ago 4 Members · 3 Replies -
3 Replies
-
Hello Shubham,
You need to create new “instance” of Account and need to add Id and RecordTypeId in it to update.
Right now in your code it is taking entire object returned from SOQL. Rather than updating same list you received from SOQL, create new list of Account and update that.
Put this line before SOQL on account.
List<Account> = new List<Account>();Wherever you are setting RecordTypeId, set following code for adding account in list of Accounts to be updated.
Account a = new Account(
Id = acc.Id,
RecordTypeId = rt.Id
);
AccListToBeUpdated.add(a);Let me know if any issues. Mark it as best answer if it works!
- [adinserter block='9']
-
List<Account> = new List<Account>();
Account a = new Account(
Id = acc.Id,
RecordTypeId = rt.Id
);
AccListToBeUpdated.add(a);May be it helps
Thanks.
-
Hi Parul,RadhaKrish
I have executed your code and it didn’t work out for me. You are using account id but you didn’t specify the source of these account id’s and Also,you didn’t specify anything about description in your apex code and you haven’t perform any DML operations as well. Below snippet of code worked for me :
list<account> accountList = new list<account>();
accountList = [select id,Description from Account Limit 100];
if(accountList.size() > 0){
for(Account acc :accountList){acc.Description = ‘Test’;
}update accountList;
}Hope this helps!
-
This reply was modified 7 years, 8 months ago by
shariq.
-
This reply was modified 7 years, 8 months ago by
Log In to reply.