You need to sign in to do that
Don't have an account?
learncloud
trying to update account object field
Hi,
I am new to sfdc, i would like o update account object field based on opportunity object field values
below is my code what i tried but im getting error. - Error: Compile Error: Variable does not exist: ac at line 20 column 8
trigger Account on Opportunity (after update)
{
if (Trigger.isUpdate)
{
list<Account> acc = new list<Account>();
for(Opportunity opp: trigger.new)
{
Account ac = new Account();
ac.Status__c = opp.StageName;
if(opp.StageName == 'Closed Won')
{
ac.Status__c = 'Customer';
}
}
update ac;
}
}
I am new to sfdc, i would like o update account object field based on opportunity object field values
below is my code what i tried but im getting error. - Error: Compile Error: Variable does not exist: ac at line 20 column 8
trigger Account on Opportunity (after update)
{
if (Trigger.isUpdate)
{
list<Account> acc = new list<Account>();
for(Opportunity opp: trigger.new)
{
Account ac = new Account();
ac.Status__c = opp.StageName;
if(opp.StageName == 'Closed Won')
{
ac.Status__c = 'Customer';
}
}
update ac;
}
}
Could you please try this and let me know if any issue occure?
trigger Account on Opportunity (after update)
{
list<Account> accLst = new list<Account>();
if (Trigger.isUpdate)
{
for(Opportunity opp: trigger.new)
{
Account ac = new Account();
ac.Status__c = opp.StageName;
if(opp.StageName == 'Closed Won')
{
ac.Status__c = 'Customer';
accLst.add(ac);
}
}
if(accLst!=null&& accLst.size()>0)
update accLst;
}
}
Can you please explain what are you trying to do here and I will see If I can help you out..
It's looks like you have field Status__c on account which needs to be same as opportunity's stage field. If yes, then one account can have many opportunities and which opportunity's stage field should be set as account's Status__c?