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

When closed the Opportunity, close its Quotes automatically
Hello,
I wrote a trigger for Opportunity. I want to do 'When closed the Opportunity, close its Quotes automatically', but it didn't work. Please help to check the code, thanks!!
trigger QuoteClose on Opportunity(after insert, after update) {
Quote[] cList = new Quote[]{};
for(Opportunity opp : trigger.new)
{if (opp.StageName == 'Closed Won')
cList.add(new Quote(OpportunityId=opp.Id, Status = 'Close'));
}
if (cList != null && !cList.isEmpty())
Database.update(cList);
}
Since the Opportunity to Quote relation is One - Many, creating just one instance of Quote per Opprtunity wont do it. You will need to query for the quotes of the Opportunities and then update them.
All Answers
Since the Opportunity to Quote relation is One - Many, creating just one instance of Quote per Opprtunity wont do it. You will need to query for the quotes of the Opportunities and then update them.
Thanks so much, it works.
I'm receiving an erro rin the trigger... :(
Error: Compile Error: Unexpected token '['. at line 3 column 3