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

Clarifiication on Trigger
This trigger is on Quote and I am stuck on one part I am not able to use IsClosed() on quote status.
trigger CloseAllQuotes on Quote (after update) {
system.debug('Close All the Quotes on the Oppurtunity after one Quote is closed');
ID Oppid = Trigger.new[0].OpportunityId;
List <Quote> newQt = new List <Quote> ();
for(Quote Qt: newQT) {
if((){ ----> I need to chk if previously this was not approved
Qt = [select id,status,OpportunityId from Quote where OpportunityId=:Oppid];
Qt.Status = 'Approved';
Update Qt;
}
}
}
Oh, i thought you wanted to check on setting approved only on current record status change.
You can use the following logic with some modifications.
Remember, your trigger need to run for bulk updates too.
trigger CloseAllQuotes on Quote (after insert,after update)
{
List <Quote> newQt = new List <Quote> ();
Set<ID> ct=new set<ID>();
for(Quote c:trigger.new)
{
if (c.status == 'Approved')
{
ct.add(c.OpportunityId);
}
}
for(Quote con :[select id,status from Quote where status != 'Approved' and OpportunityId in :ct]){
con.status = 'Approved';
newQt.add(con);
}
update newQt;
}
All Answers
You could use
if ( Trigger.oldMap.get(Qt.Status) != 'Approved')
-----------------
The standard options for quote are only:
I tried it but it throws error...please look into this
trigger CloseAllQuotes on Quote (after update) {
system.debug('Close All the Quotes on the Oppurtunity after one Quote is closed');
ID Oppid = Trigger.new[0].OpportunityId;
List <Quote> newQt = new List <Quote> ();
for(Quote Qt: newQT) {
if (Trigger.oldMap.get(Qt.Status) != 'Approved'){
Qt = [select id,status,OpportunityId from Quote where OpportunityId=:Oppid];
Qt.Status = 'Approved';
Update Qt;
}
}
}
thanks for that it accepted but the trigger is not updating status of other quotes to 'Approved'
please look at this and let me know if I am missing something
trigger CloseAllQuotes on Quote (after insert,after update) {
system.debug('Close All the Quotes on the Oppurtunity after one Quote is closed');
ID Oppid = Trigger.new[0].OpportunityId;
List <Quote> newQt = new List <Quote> ();
for(Quote Qt: newQt) {
Qt = [select id,status,OpportunityId from Quote where OpportunityId=:Oppid];
if (Trigger.newMap.get(Qt.id).status == 'Approved'){
Qt.Status = 'Approved';
Update Qt;
}
}
}
Oh, i thought you wanted to check on setting approved only on current record status change.
You can use the following logic with some modifications.
Remember, your trigger need to run for bulk updates too.
trigger CloseAllQuotes on Quote (after insert,after update)
{
List <Quote> newQt = new List <Quote> ();
Set<ID> ct=new set<ID>();
for(Quote c:trigger.new)
{
if (c.status == 'Approved')
{
ct.add(c.OpportunityId);
}
}
for(Quote con :[select id,status from Quote where status != 'Approved' and OpportunityId in :ct]){
con.status = 'Approved';
newQt.add(con);
}
update newQt;
}
thanks a lot ..it worked
I am trying to run a trigger where all of the work orders related to an opportunity must have a work order stage status of Job Completed or Work Order Closed before the opportunity is updated to Job Completed. The trigger works in that if any of the work orders are changed to Job Completed or Work Order Closed, the opportunity gets updated to Job Completed, but I want all of the work orders closed; otherwise, don't update the opportunity. Can you please take a look and see what I am missing?
Thanks!
your problem description is not clear.
When do you want to update oppurtunities?
is it only when work_order is closed?
If so, your first condition fails on how you pick your list of oppurtunities to be added to the list.
Thanks for your response. I want to update the Opportunity Stage when all of the work orders that relate to that opportunity either are marked Job Completed, Work Order Closed - Quickbooks. What I am trying to do in the trigger is when a work order is updated to either Job Completed, or Work Order Closed, create a list of opportunities affected. Check that list of opportunities to see if all the related work orders have one of the two closed values, if all related work orders do have a closed value, then mark the opportunity completed.
The trigger is working so far as updating the opportunity field, but it closes the opportunity if any work order is marked Job Completed or Work Order Closed. I cannot figure out how to check the list of all opportunities to see that all work orders related are closed. I appreciate any clarification you may provide.
the above given code would not compile well and you might be running old compiled code?
You should have .....if(allCompleted == true).... instead of ....if(allCompleted = true) ......
Other than that, code seems ok.