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

Error Trigger with Quote Id
I got a error message with my Trigger. I just want to do, if Quote's status is ''Accepted', so Opportunity's stage change to 'Closed Won' automaticlly.
trigger test on Quote(after insert, after update) {
List<Opportunity> stageToUpdate = new List<Opportunity>();
for(Quote quo : trigger.new)
{if (quo.status == 'Accepted')
stageToUpdate.add(new Opportunity(Id=quo.Id, StageName = 'Closed Won'));
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}
Error message,
execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: 0Q09000000009qYCAQ: Trigger.test: line 6, column 38
Hi,
I tried the same code in my org, its working....
I dont get the exact problem here. i'm not sure it would help, but give it a try...
Code:
trigger test on Quote (after insert, after update)
{
Set<Id> setId = new set<Id>();
List<Opportunity> stageToUpdate = new List<Opportunity>();
for(Quote objQuote : [Select OpportunityId, Name, status from Quote where status = 'Accepted' and Id In: Trigger.new])
{
if(!setId.contains(objQuote.OpportunityId))
{
setId.add(objQuote.OpportunityId);
string str = objQuote.OpportunityId;
stageToUpdate.add(new Opportunity(Id=str.substring(0,15), StageName = 'Closed Won'));
}
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}
Thanks
All Answers
Try this
this would work only for one quote.
trigger test on Quote(after insert, after update) {
List<Opportunity> stageToUpdate = new List<Opportunity>();
Opportunity opp = [select id, name,StageName from opportuntiy where id:=tirgger.new[0].opportunity];
for(Quote quo : trigger.new)
{if (quo.status == 'Accepted')
opp.StageName = 'Closed Won';
stageToUpdate.add(opp));
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}
Thanks, it show a error info.
Severity and Description Path Resource Location Creation Time Id
Save error: Invalid bind expression type of SOBJECT:Opportunity for column of type Id test/src/triggers test.trigger line 4 1302196655625 147
Opportunity opp = [select id, name, StageName from opportunity where id=:trigger.new[0].opportunity];
Did you try this
Opportunity opp = [select id, name, StageName from opportunity where id=:trigger.new[0].opportunity.id];
Sorry, when I save Quote, it said test: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.test: line 4, column 19
Anyone can help me?
Hi,
try this.. hope it help.
trigger test on Quote(after insert, after update)
{
Set<Id> setId = new setId();
List<Opportunity> stageToUpdate = new List<Opportunity>();
for(Quote objQuote : [Select OpportunityId, Name, status from Quote where status = 'Accepted' and Id In: Trigger.new])
{
if(!setId.contains(objQuote.OpportunityId))
{
setId.add(objQuote.OpportunityId);
stageToUpdate.add(new Opportunity(Id=quo.Id, StageName = 'Closed Won'));
}
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}
Thanks
Hi,
I tried the same code in my org, its working....
I dont get the exact problem here. i'm not sure it would help, but give it a try...
Code:
trigger test on Quote (after insert, after update)
{
Set<Id> setId = new set<Id>();
List<Opportunity> stageToUpdate = new List<Opportunity>();
for(Quote objQuote : [Select OpportunityId, Name, status from Quote where status = 'Accepted' and Id In: Trigger.new])
{
if(!setId.contains(objQuote.OpportunityId))
{
setId.add(objQuote.OpportunityId);
string str = objQuote.OpportunityId;
stageToUpdate.add(new Opportunity(Id=str.substring(0,15), StageName = 'Closed Won'));
}
}
if (stageToUpdate != null && !stageToUpdate.isEmpty())
Database.update(stageToUpdate);
}
Thanks
Finally! Finally! It works!!
Thanks soso much:-)
Could you also use a similar method to update the SyncedQuoteID field on the opportunity with the Quote ID when a quote is created?
-Justin