You need to sign in to do that
Don't have an account?
Dave The Rave
Convert DML Statement to Apex Class
As a admin, I have created a DML Statement to run in the Developer Console adhoc whenever I need to change account record owners en mass.
Now I need to convert that into an Apex Class and Trigger so that when records are uploaded from an external party the account record owner will be changed automatically based on shippingcity. See DML Code below:
3rd Party OwnerID = '0052o00000AHDCeEAP'
New record owner = '0052o00000AI4zfACD'
Now I need to convert that into an Apex Class and Trigger so that when records are uploaded from an external party the account record owner will be changed automatically based on shippingcity. See DML Code below:
List<Account> recList = [select id, shippingcountry, ownerid, name, shippingcity FROM Account WHERE shippingcountry = 'NL' AND sasid__c = null and ownerid='0052o00000AHDCeAAP' AND shippingcity IN ('Nijmegen','Arnhem')]; for (Account rec : recList) { rec.ownerid = '0052o00000AI4zfAAD'; } update recList;
3rd Party OwnerID = '0052o00000AHDCeEAP'
New record owner = '0052o00000AI4zfACD'
Hi Dave,
Although hard-coded Id's are not recommended in code (code would break in different salesforce instances, user deactivation, etc), I'm writing the trigger snippet below to help you get started
Hope it helps!
All Answers
Greetings!
Please find the document for the sample example which might help you to proceed further on this.
https://www.tutorialspoint.com/apex/apex_dml.htm
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Hi Dave,
Although hard-coded Id's are not recommended in code (code would break in different salesforce instances, user deactivation, etc), I'm writing the trigger snippet below to help you get started
Hope it helps!
Hi Dave,
In an ideal world, all business logic should like in an apex class which is then called by the apex trigger. We call these classes trigger helpers. But again, it's a best practice and not the only way to write code.
I hope this answers your question.
Also, if your original query is resolved, please mark the right answer as the best answer to help others.
Regards,
Vishal