You need to sign in to do that
Don't have an account?
Laxman Rao
How to update sObject Dynamically?
Hi ,
When i try to update the sobject dynamically it throws me a error saying "System.SObjectException: Field Id is not editable". Can you please help on this:
I have used the below code to update :
Schema.SObjectType t = Schema.getGlobalDescribe().get('Account');
SObject sObjectAccount = t.newSObject();
sObjectAccount.put('Id', '001G000000pyDGL');
sObjectAccount.put('Name', 'Test');
Update sObjectAccount;
thanks for replying.
If we remove the Id it will insert the record, I want the record to update.
I have queried the corresponding record from Account and I have updated using this :
String query = 'Select Id From Account Where Id = \'001G000000pyDGL\'';
system.debug(query );
Sobject sObjectAccount = Database.Query(query);
sObjectAccount.put('Name', 'Test.');
All Answers
You cannot edit or set ID field.
Remove sObjectAccount.put('Id', '001G000000pyDGL');
Cheers !!!
Regards,
Magulan D
Salesforce.com certified Force.com Developer.
SFDC Blog
If this post is your solution, kindly mark this as the solution.
thanks for replying.
If we remove the Id it will insert the record, I want the record to update.
I have queried the corresponding record from Account and I have updated using this :
String query = 'Select Id From Account Where Id = \'001G000000pyDGL\'';
system.debug(query );
Sobject sObjectAccount = Database.Query(query);
sObjectAccount.put('Name', 'Test.');
You don't need to query the record - you can do this:
Hi,
Thanks for the solution.