+ Start a Discussion
Chris987654321Chris987654321 

Dynamic Updates

Is it possible to do dynamic SOQL statements do updates similar to how you do Select statements like this Database.query like Database.update

Best Answer chosen by Admin (Salesforce Developers) 
soofsoof

Salesforce.com database follows an Object-Oriented pattern, so SQL-style insert/udpate statements are not available.  However, you CAN dynamically update records in the following manner:

 

SObject cs = new Case();

cs.put('Subject', 'Mouse Error');

cs.put('Description', 'I cannot move my mouse pointer');

cs.put('Status', 'New');

cs.put('Field_Name1__c', 'Field Value 1');

cs.put('Field_Name2__c', 'Field Value 1');

cs.put('Field_Name3__c', 'Field Value 1');

update cs;

 

Check out the docs:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_dml.htm

 

Hope this helps!

 

-soof 

 

 

All Answers

soofsoof

Salesforce.com database follows an Object-Oriented pattern, so SQL-style insert/udpate statements are not available.  However, you CAN dynamically update records in the following manner:

 

SObject cs = new Case();

cs.put('Subject', 'Mouse Error');

cs.put('Description', 'I cannot move my mouse pointer');

cs.put('Status', 'New');

cs.put('Field_Name1__c', 'Field Value 1');

cs.put('Field_Name2__c', 'Field Value 1');

cs.put('Field_Name3__c', 'Field Value 1');

update cs;

 

Check out the docs:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_dml.htm

 

Hope this helps!

 

-soof 

 

 

This was selected as the best answer
Chris987654321Chris987654321
Thanks! That worked great.