function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BNB BaluBNB Balu 

What is diff between Static DML and Dynamic DML queries?give some examples

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Balu,

May I request you to please refer the below link for reference. I hope it will be helpful.

Best Regards
Rahul Kumar
Shiva RajendranShiva Rajendran
Hi Balu,

Using static DML you generally manually type all the fields required for the object in the soql query . 
It requires lot of manual work.
It doesn't work based on user privelege like say if employee user shouldn't see money field of user while manager should see ,you will have different profile for each user
Now at code level
you may have to write two queries
List<Account> soqlQueryResult
if(user==manager)
{
soqlQueryResult=[select id,money from account];
}
else
{
soqlQueryResult=[select id,name from account];
}
if you fetch with money on the normal user who dont have privelege to read you will get errors on the soql query
Here come's the dynamic dml,
You can dynamically choose the fields based on the preveliges on the soql
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_dml.htm
Do read those documents
Do let me know if you need further help.


Thanks and Regards,
Shiva RV
 
Shiva RajendranShiva Rajendran
This link explains the dynamic loading of fields using dynamic dml
http://www.sfdcpoint.com/salesforce/dynamic-soql-query-fetch-fields-object-salesforce/
Similar way you can load fields based on user profile previleges
Thanks and Regards,
Shiva RV