function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Veerendar AellaVeerendar Aella 

Need a trigger to more quote status from ready to price to Proposed when a quote option is created

Hi All, I want a trigger to move quote status from ready to price to proposed when a quote option is created. Here Quote is the Parent Object and Quote Option is the child. So, when ever a quote option is created, I want to move my quote status to proposed. Please hlep.
Please also need test class for the trigger.
Best Answer chosen by Veerendar Aella
Andrew GAndrew G
When you say the debug log shows nothing, have you added any debug lines to the Trigger?
Below is perhaps over the top with Debug lines, but it will definitely show something in the debug logs, especially whilst trouble shooting.  They can be removed or commented out once the issue is resolved.

Based on the debug lines, you can then determine at what point the trigger is not working correctly.
 
trigger updateQuoteStatus on Quote_Option__c(after insert){

    System.debug ('##DEBUG: in trigger updateQuoteStatus ');

    List<Quote> quoteListToUpdate = new List<Quote>();
    set<id> quoteIds = new set<id>();
    for(quote_option__c qO : trigger.new){
        quoteIds.add(qO.Quote__c);
    }
    System.debug ('##DEBUG: number of related quotes ' + quoteIds.size());

    List<Quote> quoteList = [SELECT id,Status FROM quote where id in:quoteIds];
    System.debug ('##DEBUG: quote list after SELECT ' + quoteList.size());

    for(Quote qo : quoteList){
        System.debug ('##DEBUG: in the Quote loop');
        qo.status ='proposed';
        quoteListToUpdate.add(qo);
    }

    if(quoteListToUpdate.size()>0){
        System.debug ('##DEBUG: we have quotes to update');
        update quoteListToUpdate;
    } else {
        System.debug ('##DEBUG: we had NO quotes to update');
    }
}

As for why Process Builder is not firing, what was the criteria at your decision point?  Did you use the ISNEW() as i suggested, or are you setting it to fire regardless?  
I will do a test in an environment to confirm that the Process Builder will work on those objects, but I have used the same logic on other objects in the SF environment.

regards
Andrew
 

All Answers

Andrew GAndrew G
Could you not use Process Builder?

On create of Quote Option
Decison point Criteria  - FOrmula evaluates to true - ISNEW()
action - Recored [QuoteOption].QuoteID
FIlter records Status Equals Picklist "Ready to Price"
Set new field values
Status Equals Picklist "Proposed"


Regards
Andrew
Veerendar AellaVeerendar Aella
Hi Andrew,
Thanks for help but some how process builder is not moving it to proposed, i have tried all the options with process builder.
I want to use Trigger for this.
abhishek singh 497abhishek singh 497
Hello Veerendar,
Please try the code below in your Org.
I have tested in my org and it's working fine.

trigger updateQuoteStatus on Quote_Option__c(after insert){
    List<Quote> quoteListToUpdate = new List<Quote>();
    set<id> quoteIds = new set<id>();
    for(quote_option__c qO : trigger.new){
        quoteIds.add(qO.Quote__c);
    }
    List<Quote> quoteList = [SELECT id,Status FROM quote where id in:quoteIds];
    for(Quote qo : quoteList){
        qo.status ='proposed';
        quoteListToUpdate.add(qo);
    }
    if(quoteListToUpdate.size()>0){
        update quoteListToUpdate;
    }
}

Please let me any further concerns.
If you find it good enough, please mark it as best one.

Thanks & Regards,
Abhishek Singh.
Veerendar AellaVeerendar Aella
Hi Abhishek,
The above trigger is also not working, Quote status is not moving from 'ready to Price' to 'Proposed' when quote option is created.
abhishek singh 497abhishek singh 497
Hello Veerendar,

I have tested in my developer account and it's working fine in my Org.

Please make sure a few things:-
1) quote option must have a look-up or master-detail relationship with the quote.

Please let me know any further queries.

Thanks,
Abhishek Singh.
Veerendar AellaVeerendar Aella
Hi Abhishek,

Yes, quote option has master detail relationship with the quote, but still the status is not changing, degug log shows nothing. I tried with Process builder, it is also not firing when quote option is created but when quote option fileds edited it is moving the status to proposed. Wondering what might be the issue here?
Andrew GAndrew G
When you say the debug log shows nothing, have you added any debug lines to the Trigger?
Below is perhaps over the top with Debug lines, but it will definitely show something in the debug logs, especially whilst trouble shooting.  They can be removed or commented out once the issue is resolved.

Based on the debug lines, you can then determine at what point the trigger is not working correctly.
 
trigger updateQuoteStatus on Quote_Option__c(after insert){

    System.debug ('##DEBUG: in trigger updateQuoteStatus ');

    List<Quote> quoteListToUpdate = new List<Quote>();
    set<id> quoteIds = new set<id>();
    for(quote_option__c qO : trigger.new){
        quoteIds.add(qO.Quote__c);
    }
    System.debug ('##DEBUG: number of related quotes ' + quoteIds.size());

    List<Quote> quoteList = [SELECT id,Status FROM quote where id in:quoteIds];
    System.debug ('##DEBUG: quote list after SELECT ' + quoteList.size());

    for(Quote qo : quoteList){
        System.debug ('##DEBUG: in the Quote loop');
        qo.status ='proposed';
        quoteListToUpdate.add(qo);
    }

    if(quoteListToUpdate.size()>0){
        System.debug ('##DEBUG: we have quotes to update');
        update quoteListToUpdate;
    } else {
        System.debug ('##DEBUG: we had NO quotes to update');
    }
}

As for why Process Builder is not firing, what was the criteria at your decision point?  Did you use the ISNEW() as i suggested, or are you setting it to fire regardless?  
I will do a test in an environment to confirm that the Process Builder will work on those objects, but I have used the same logic on other objects in the SF environment.

regards
Andrew
 
This was selected as the best answer
Andrew GAndrew G
I have tested Process Builder.  It works.
Interestingly, if I do process builder on creation of a quote line item, the quote page refreshes immediately and i can see both the status field and the kanban indiciator update.  But if I created  a Quote Option (Custom object), I needed to close and reopen the quote to see the status change.

But , yes, it works.  So i suggest you recheck how you have done the process builder.

Regards
Andrew
Veerendar AellaVeerendar Aella
Hi Andrew, 
Thanks many thanks, It worked, can you please send me the test class for the same.