You need to sign in to do that
Don't have an account?
Petya
Trigger to update the quote status
Hi
I try to make my first trigger, that should update the Quote Satus to "Approved", when the Opportunity is approved. Here the code:
trigger OppTriggers on Opportunity (after update) {
or(Opportunity opp: Trigger.new){
List<Quote> listQ = [SELECT Id, Opportunity.Account.Id,
Opportunity.TEM_Approval_Confirmed_RD__c FROM Quote WHERE id =: Quote.Id];
for(Quote q : listQ){
Quote.Status = "Approved";
}
update listQ;
} }
Any Suggestions would be appreciated
Thanks
hai i worked this i just wrote the sample one.
replace the foeld name as u want ..
this is working fine and please let me know once u got executed and ask doubts if u have? or else provide ur email address. so that i can help u .
here is your code
trigger quote_update on Quote (after update) {
Set<String> quote_ref=new Set<String>();
for(Quote qq : Trigger.new)
{
if(qq.Status=='Approved')
quote_ref.add(qq.OpportunityId);
}
for(Opportunity oo : [select id, StageName from Opportunity where id in: quote_ref])
{
oo.StageName='Closed Won';
update oo;
}
}
All Answers
Hi,
Please don't place any SELECT clauses (and also DMLs) inside FOR loop.
You can have the below line above the the for loop.
List<Quote> listQ = [SELECT Id, Opportunity.Account.Id,
Opportunity.TEM_Approval_Confirmed_RD__c FROM Quote WHERE id =: Quote.Id];
I think you didnot paste the complete code as I don't see any way Quote.Id in the select clause getting populated.(or having value)
Thanks,
JBabu.
Hi and many thanks :)
here is my code with correction:
trigger QuoteTriggers on Quote (after update) {
List<Quote> listQ = [SELECT Id, Opportunity.Account.Id,
Opportunity.TEM_Approval_Confirmed_RD__c FROM Quote WHERE id =: Quote.Id];
for(Opportunity opp: Trigger.new){
for(Quote q : listQ){
Quote.Status = 'Approved';
}
update listQ;
} }
I need the Trigger on the Quote Object ofcourse to get the quoteID. But it still doesnt work,
"Invalid bind expression type of Schema.SObjectField for column of type Id on line 3"...
Hi,
Please use the below code:
trigger QuoteTriggers on Quote (after update) {
List<Quote> listQ = [SELECT Id, Opportunity.Account.Id,
Opportunity.TEM_Approval_Confirmed_RD__c FROM Quote WHERE id IN :trigger.New];
for(Quote q : listQ){
q.Status = 'Approved';
}
update listQ;
}
Also I dont see any logic in your code that this quote approved needs to be done for related opportunity approved records. If you want that condition you need to write logic for that one.
Thanks,
JBabu.
Thank you for your help
the idea was to check the condition „Opportunity.Approval_Confirmed_c,“ when the condition is true, the opportunity is approved, and then the quote status should be set to approved, because when that happens I could send the quote via email and this is only possible by me, when the quote is approved.
I tried to make this with workflow, but it doesn't work, how I wish. With a workflow the quote status will be updated only when the quote is edited or created, and I need to see the changes after updating the opportunity without editing the quote.
Thanks
So did the above suggested code work?
yes, it works :)
but I think, I must insert an If -Condition
if(Opportunity.TEM_Approval_Confirmed_RD__c=True){
for(Quote q : listQ){
q.Status = 'Approved';
}
update listQ;
}
and many quotes can be defined to an Opportunity, I must define an area.
the code doesnt work, i can compile it but, if I set the Opportunity to approved, the quote status does not changed, and if I open the quote and try to edit and save it, I receive Error Message from the trigger...
Hi,
What is the error message and can you share the complete code which you used?
Thanks,
JBabu.
Hi
I have this code
2
3
4
5
6
7
8
9
10
11
12
13
14
trigger QuoteTriggers on Quote (before update) {
List<Quote> listQ = [SELECT Id, Opportunity.Account.Id,
Opportunity.TEM_Approval_Confirmed_RD__c FROM Quote WHERE id IN :trigger.New];
for(Quote q : listQ){
if (q.Opportunity.TEM_Approval_Confirmed_RD__c = True) {
q.Status = 'Approved';
}
update listQ;
}
}
this is the error message
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger QuoteTriggers caused an unexpected exception, contact your administrator: QuoteTriggers: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0Q0W00000004FdKKAU; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, QuoteTriggers: maximum trigger depth exceeded Quote trigger event AfterUpdate for [0Q0W00000004FdK] Quote trigger event AfterUpdate for [0Q0W00000004FdK] Quote trigger event AfterUpdate for [0Q0W00000004FdK]
Thanks
hi,
remove the if condition and place that in the select like
select your query where Opportunity.TEM_Approval_Confirmed_RD__c=True limti 1];
now try this,
hi and thanks :) I still receive an errormessage...
hai i worked this i just wrote the sample one.
replace the foeld name as u want ..
this is working fine and please let me know once u got executed and ask doubts if u have? or else provide ur email address. so that i can help u .
here is your code
trigger quote_update on Quote (after update) {
Set<String> quote_ref=new Set<String>();
for(Quote qq : Trigger.new)
{
if(qq.Status=='Approved')
quote_ref.add(qq.OpportunityId);
}
for(Opportunity oo : [select id, StageName from Opportunity where id in: quote_ref])
{
oo.StageName='Closed Won';
update oo;
}
}
You can even do things like change certain characters or words to other characters or words if they are inside quotes. Use the Advanced Editor on this site to test some of these examples without actually putting them into your document. kezia pickuplines com (https://keziapickuplines.com/best-christian-pickup-lines/)
Steps to reproduce:
1) Create any article with field codes in it (a basic 'Hello World' would do).
2) Within that article, enclose some text between single quotes (e.g., 'text').
3) Click the "Insert" tab to the top row of ribbon tabs.
4) Click on the dropdown arrow beside "Quick Parts" (about halfway down).
5) Click on "Field Codes", then click again on the little square with ellipses to open up the Field dialog.
6) Choose whatever code you want, but be sure to check the box that says "Process as soon as it is typed". This will process whatever code you use as soon as it's typed into your document, so choose something short and simple, like ~*bold*~ to test. Don't choose something longer because no one wants their field code processors to run every time you type a sentence! :)