You need to sign in to do that
Don't have an account?
Stuart Turnbull 9
Apex Trigger to update an Account field from a Lookup on the same Account
We are trying to Copy the Lookup field value on an Acount into another field on that same Account.
The error occurs at Line 6
Invalid field Account for SObject Account
I'm new to Apex Programming, and a bit unsure if this is the right solution..I did some research, but only found Discussions on updating a Lookup from one Object to a field in another Object. Can someone offer further guidance? Are there any other articles out the there for copying a Lookup to another field in the same Object?
The error occurs at Line 6
Invalid field Account for SObject Account
I'm new to Apex Programming, and a bit unsure if this is the right solution..I did some research, but only found Discussions on updating a Lookup from one Object to a field in another Object. Can someone offer further guidance? Are there any other articles out the there for copying a Lookup to another field in the same Object?
At line 6, change the code like this: Because you have created a Set<Id> and you are trying to pass invalid field. acct.Account as Account object doesn't have any Account field.
Also you might get exception at line 9, beacuse what is Account2.
Thanks,
Neetu
I adjusted the Code, updating Line 6, and correcting Account2 to Account in Line 9, and now recive the same message as before, but at line 5
Invalid field Account for SObject Account
Thanks.
Please update the code at line 5 also like this:
if( acct.Id != null )
Although you don't need to put that check, as Id will always be populated in after insert/update call.
Thanks,
Neetu
I made the adjustment, and it now references an exception at Line 12
Initial term of field expression must be a concrete SObject: Set<Id>
I modilfied LIne 12 from
Campus__c from Account where ID IN: Account.Campus__c]);
To
Campus__c from Account where ID IN: ID]);
and now...
Variable does not exist: ID
Is Campus__c is a look up field and Campus_For_Campaigns__c is Text field, which store Campus__c Id. If yes, You can achieve this by creating formula field. but if you need to write trigger. Try this code:
Thanks,
Neetu
Actually, it is not the ID, but the specific set of Account Names associated with the ID (based on RecordType).
Thank you.
If you want to bring the data from the lookup object (Campus__c) then there is no need for the trigger, you can create a formula field on the Account and get the values you need. Here is the example of the expression for the formula field.
Campus__r.Name
The above expression will display the value of the Name field of the lookup object (Campus__c).
You can change the field names, or concatenate other field values also as below.
Campus__r.Name + ' ' + Campus__r.field2 + ' ' + Campus__r.field3
Change the field names accordingly.
Hope this helps.