You need to sign in to do that
Don't have an account?
Emily Petersen 13
I need to create an APEX code that updates the Account Owner based on the Contact ID of a name in another field that is not currently linked to a Contact ID
I need assistance writing APEX code to update the Account Owner based on the following:
Create workflow or process builder to change account owner once "commission end date" (Commission_End_Date__c) has passed. (I've already started the Process Builder, just need to add in the APEX code as the Action)
- If Account Strategist (Account_Strategist__c)(picklist field) is on an account, they are made the account owner.
- If only a Media Strategist (Media_Strategist__c)(picklist field) is on an account, they are made the account owner.
- If no Media Strategist or Account Strategist, Client Success (user) are made the account owner.
I'm assuming I need to make some sort of map that has all of the names and their corresponding Contact IDs. I have the schematics in my mind, I just don't know how to follow through. Any help would be greatly appreciated!!
Best,
Emily
Create workflow or process builder to change account owner once "commission end date" (Commission_End_Date__c) has passed. (I've already started the Process Builder, just need to add in the APEX code as the Action)
- If Account Strategist (Account_Strategist__c)(picklist field) is on an account, they are made the account owner.
- If only a Media Strategist (Media_Strategist__c)(picklist field) is on an account, they are made the account owner.
- If no Media Strategist or Account Strategist, Client Success (user) are made the account owner.
I'm assuming I need to make some sort of map that has all of the names and their corresponding Contact IDs. I have the schematics in my mind, I just don't know how to follow through. Any help would be greatly appreciated!!
Best,
Emily
I have made some changes and tested in my Org. It is working well.
Please Replace the string "Name of Owner" with the Actual Names of Owner.
Please let me know if face any issue.
Thanks
Ajay
Email: mishraajay.m1@gmail.com
All Answers
If you create a Map and Put values in that map then you will not able to change them in production if any changes needed in future.
So, Please find some below Steps. In which you can overcome this limitation.
1. First Create Custom Setting with Type List. Create Text field Owner
2. Click on Manage in Custom Setting you created, and put your all the values in the Setting.
Note: Keep in mind NAME is Key to get the Owner.
3. Create Custom Labels for All the Owners using OwnerName1, OwnerName2...........OwnerName100. 100 is just for Example you can use as much you want.
Please let me know if you any question.
Thanks
Ajay Mishra
Email: mishraajay.m1@gmail.com
Best,
Emily
Do I need to enter something where you have *list of account records*?
07 for(Account accObj : /*List of Account Records*/)
One more thing...Client Success is an actual User in the Account Owner field. So the logic is that if there's no Media Strategist and no Account Strategist, it will go to the Client Success user. I changed the code to this, will it work?
if(accObj.Media_Strategist__c == null & accObj.Account_Strategist__c == null)
{
accObj.OwnerId = mapAccountOwner.get(label.OwnerName7).Owner__c;
}
I have made some changes and tested in my Org. It is working well.
Please Replace the string "Name of Owner" with the Actual Names of Owner.
Please let me know if face any issue.
Thanks
Ajay
Email: mishraajay.m1@gmail.com