You need to sign in to do that
Don't have an account?
Laura Babb 4
invocable method not updating records as expected
I need to nail down this invocable method (or even convert to a trigger?). Not sure. I am an Admin, not a Developer, so I need help! A kind developer wrote this method for me and I am trying to trigger it via PB, but the contact owner does not update.
The PB is:
Account object (created or edited) >>
Criteria node = Account.Demand_Gen_Owner__c IS CHANGED || Account.OwnerId IS CHANGED >>
Immediate action = Apex Class
The PB is:
Account object (created or edited) >>
Criteria node = Account.Demand_Gen_Owner__c IS CHANGED || Account.OwnerId IS CHANGED >>
Immediate action = Apex Class
global class UpdateContactsFromAccount { @InvocableMethod(label='save info' description='Update Contact Owners') global static void saveInformation (List<Id> accountIds) { List<Account> listAccount = [Select Id, Demand_Gen_Owner__c, OwnerId FROM Account WHERE Id In :accountIds]; List<Contact> listContact = [Select Id, AccountId, OwnerId FROM Contact WHERE AccountId In :accountIds]; Map<Id, Account> mapIdToAccount = new Map<Id, Account>(); mapIdToAccount.putAll(listAccount); System.debug('Accounts for which Contacts to be updated:: mapIdToAccount : ' + mapIdToAccount); for(Contact con: listContact){ if(con.AccountId != null){ Account acc = mapIdToAccount.get(con.AccountId); if(acc.Demand_Gen_Owner__c != 'Unassigned' || acc.Type != 'Current Customer'){ con.OwnerId = acc.Demand_Gen_Owner__c; } else { con.OwnerId = acc.OwnerId; } } } update listContact; } }Currently this is just a PB in production and it is causing errors intermittently (usually accounts that have a ton of contacts) or also during bulk uploads. I think it's too many contact records that it's trying to update. Also have an issue with an unrelated managed package triggering the process and causing insert/update errors on the package fields (none of these fields are part of my process). I came here with this originally and it was recommended to use an invocable method/apex class to better control the updates. Please help so I can get this into prod! As always, thanks so much!
Try this:
On line 15, we need the Type field. This is the error that am seeing as of now and checking against that user created on line 4. Copy that SOQL and execute in the query editor and make sure it is returning the correct ID of that Unassigned user, just in case.
Change this and let me know. Unfortunately I don't have those many contacts on each account in my dev org to do the testing. :(
All Answers
What is the data type of the field - Demand_Gen_Owner__c?
If it is a lookup to the User object, on line 14 - you can't do that check.
If it is a text field, on line 15 - you can't do that because con.OwnerId is a Lookup field to the user object.
Demand_Gen_Owner__c is a lookup to the User object ("Unassigned" is a user in our instance). The reason I say that Demand Gen Owner does not equal 'Unassigned' is because if Demand Gen Owner DOES equal (or is changed to) Unassigned, then the related contacts should then be owned by the Account Owner. If Demand Gen Owner equals (or is changed to) any other user, then the related contacts should be owned by the Demand Gen Owner.
Try this:
On line 15, we need the Type field. This is the error that am seeing as of now and checking against that user created on line 4. Copy that SOQL and execute in the query editor and make sure it is returning the correct ID of that Unassigned user, just in case.
Change this and let me know. Unfortunately I don't have those many contacts on each account in my dev org to do the testing. :(
We are trying to make the Demand_Gen_Owner a contact owner if the Demand_Gen_Owner is NOT an Unassigned user OR Account type can be anything except Current Customer, correct me if am wrong.
Since it's an update on the related object - you wouldn't need to set any Invocable variables as far as I think. All you need is the UserId which we can get it in the code.
So, after updating, is it the same error that you were facing before or it's just not updating the contact owner?
It's not an error, it's just not updating.
Criteria node = Account.Demand_Gen_Owner__c IS CHANGED || Account.OwnerId IS CHANGED >>
Immediate action = Apex Class (no apex variables set)
Earlier I thought you were asking about additional apex variables, my bad.
Did you mean assign the specific contact to an Account? (not Account Owner) If you think this requirement should be carried out along with this then obviously in the Invocable class. Otherwise, I'd go for a trigger.
And with the contact checkbox, Sales Requested Follow Up, if that box is checked, specific contact (not all related contacts) should change to Account Owner. Assuming the account is not a current client and has a Demand Gen Owner populated (not Unassigned), there could be potentially a mix of contacts owned by the account owner (have the sales requested follow up box checked) and contact owned by the demand gen owner (checkbox is false).
Is this possible to incorporate in the invocable class?
Create a new invocable method in the same class with @Invocablemethod and perform your logic. The only reason we aren't going for trigger is because you're looking for a change in only teo particular fields.
Also, mark a best answer if you think the question is solved. :)