You need to sign in to do that
Don't have an account?
pdvapor
Setting Account Lookup with Trigger
I am trying to set an Account Lookup field on all Accounts owned by Contacts who are Portal Users under an Account.
Essentially, Portal User A is under Account A. When I update Account A, I want to update all of Portal User A's Accounts with the Account A Account Id. Can't seem to get this to work. Any advice?
trigger UpdateClientAccount on Account (after update) { Set<Id> acctId = new Set<Id>(); for (Account acct : Trigger.new) acctId.add(acct.id); Map<Id, Contact> contacts = new Map<Id, Contact>( [select id from contact where id in :acctId]); Map<Id, User> users = new Map<Id, User>( [select id from user where id in :Trigger.oldMap.keySet()]); for (Account accounts : [select Owner_s_Client_Account__c from Account where OwnerId in :Trigger.oldMap.keySet()]) accounts.Owner_s_Client_Account__c = acctId; }
One change in your trigger see this in below code, // filter according to contactid
Could you please elaborate more what do you want to update in this trigger, could not get from your question.
This is a tough one. Essentially, I want to update the Account Owned by Portal Users by the Portal User Contact Account.
And I want to update it to the Account ID that is the record I am currently updating.
Still can not understand let me ask via an example
Account : Acc1
has 3 Contacts
Con1 , Con2 , Con3
Con1 and Con2 has portal users enabled U1 and U2 respectively
What would be the value of
Owner_s_Client_Account__c field on Account after update trigger executed.
Account : Acc1
has 3 Contacts
Con1 , Con2 , Con3
Con1 and Con2 has portal users enabled U1 and U2 respectively
U1 is the Owner of Account 2 and Account 3
U2 is the Owner of Account 4 and Account 5
When the trigger is executed, Owner_s_Client_Account__c field on Account 2, Account 3, Account 4, and Account 5 is the Id of Acc1.
Thanks again for your help!
Also to help, here is what I am intending to do in the Trigger.