You need to sign in to do that
Don't have an account?

How can I use a lookup-field value in Trigger code?
Hello,
I'm trying to update an Account record by using an Opportunity "after update" trigger.
I want to update the Account record, which has the same id as the id of the Opportunity Account Name.
My code is as follows:
trigger changeAccountToActive on Opportunity (after update) {
Opportunity[] opp = trigger.new;
Account[] acct;
acct = [select id, Active__c from Account where id = :opp[0].Account.id];
//acct = [select id, Active__c from Account where Site = :opp[0].NextStep];
if (acct.size()>0)
{
if (opp[0].status__c == 'Full Payment')
{
acct[0].Active__c = 'Yes';
}
update acct[0];
}
}
acct = [select id, Active__c from Account where id = :opp[0].Account.id];
//acct = [select id, Active__c from Account where Site = :opp[0].NextStep];
if (acct.size()>0)
{
if (opp[0].status__c == 'Full Payment')
{
acct[0].Active__c = 'Yes';
}
update acct[0];
}
}
I used some debug printing code and I realised that the code doesn't get the lookup field value, but it does get the values of other fields. If I use the code in comments, where the "where" statement works on another opportunity field, it works...
Does anyone have an idea???
Thanks.
Message Edited by NM on 01-19-2008 10:57 PM
Message Edited by NM on 01-19-2008 11:00 PM
acct = [select id, Active__c from Account where id = opp[0].AccountId];
Message Edited by NM on 01-22-2008 03:28 AM
when you look the API Name of field account in Opportunity fields list, you will get the API Name as AccountId. System uses the API name to access values of fields.