You need to sign in to do that
Don't have an account?
Nathan Prats 22
Avoid “Apex CPU time limit exceeded” - Trying to use a map
Hi,
I have this code that doesn't work. I'm trying to convert it as a map as I read in the best practices that I should use maps.
The custom field Contact_Owner_Account_Owner__c returns TRUE when the ownerId is different from the account ownerId.
Nathan
I have this code that doesn't work. I'm trying to convert it as a map as I read in the best practices that I should use maps.
The custom field Contact_Owner_Account_Owner__c returns TRUE when the ownerId is different from the account ownerId.
List<Contact> ContList = [SELECT Id,OwnerId,Account.OwnerId,Contact_Owner_Account_Owner__c FROM Contact WHERE Contact_Owner_Account_Owner__c = TRUE AND AccountId != '']; for(Contact Cont : ContList){ Cont.OwnerId = Cont.Account.OwnerId ; } update ContList;Thanks for your help,
Nathan
Correct code is this, with the DML in the middle
All Answers
I tried this code in the execute anonymous window but I'll use it as a Scheduled Apex in order to reassign contacts to the account owner each morning at 8AM for example. It's supposed to maintain our data quality.
Create a Workflow on Contact, set criteria to 'created and every time it's edited'
Use formula
Immediate Action:
Field Update
OwnerId = Account.OnwerId
Activate Workflow. Done.
Mark this as Best Answer, if this solves your problem.
Correct code is this, with the DML in the middle