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
Nikki Hagen 3Nikki Hagen 3 

Update to an existing trigger...switching from a custom quote object to the standard quote object

Good afternoon.  Before I start contracting work out, I thought I would ask here.  We have a custom object for quotes and we are in the process of switching to the standard object.  During our original implementation, a trigger was built so that everytime a quote was created, or a subsequent quote was created on an opoortunity, it would give the quote a "number" which in turn, make that number a letter.  So, you end up with quote revisions.  

So on the trigger, I no longer want to reference the customer quote object (in bold), I want to reference the standard which would be Quote__c (I assume).  Here is a small portion of the trigger as it is today.  When I change the bold text to Quote__c, this is the error:[Error] Error: Compile Error: Invalid SObject type name: Quote__c at line 1 column 32

trigger PrimaryQuoteTrigger on SFDC_520_Quote__c (before insert, before update, before delete, after insert, after update) {
    // Rules:
    // #1 Can't delete primary quote
    // #2 Primary quote cannot be un-marked primary. A different existing quote must be marked primary which will unmark the others.
    // #3 Only one primary quote per oppy
    // #4 First quote on oppy must be primary

Any help would be appreciated.  Thanks, Nikki ~
 
Best Answer chosen by Nikki Hagen 3
Cyrus TalladenCyrus Talladen
This was probably caused because likely you hardcoded the change on the Trigger itself.  But the metadata for that Trigger may still contain information of the old Trigger which is why the compiler is now complaining.  What I would do is to create the new Trigger on the salesforce setup page itself or make a new trigger on an IDE with your changes.

Cyrus T
www.levementum.com

All Answers

Cyrus TalladenCyrus Talladen
This was probably caused because likely you hardcoded the change on the Trigger itself.  But the metadata for that Trigger may still contain information of the old Trigger which is why the compiler is now complaining.  What I would do is to create the new Trigger on the salesforce setup page itself or make a new trigger on an IDE with your changes.

Cyrus T
www.levementum.com
This was selected as the best answer
BalajiRanganathanBalajiRanganathan
it should be Quote and not Quote__c. only custom fields and objects ends with __c
 
Nikki Hagen 3Nikki Hagen 3
Balaji, I already tried using Quote and I get the following error:   
Error: Compile Error: Entity is not api accessible at line 1 column 32
Nikki Hagen 3Nikki Hagen 3
Cyrus, I did what you said and created the new trigger and I didnt get any errors.  AWESOME!  :)  I then created the new records that should fire off the triggers and this is what I get.  Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger StandardQuoteRevisionNumTrigger caused an unexpected exception, contact your administrator: StandardQuoteRevisionNumTrigger: execution of BeforeInsert caused by: System.StringException: Invalid id: 6018393: External entry point

Above  the number (6018393) is the opportunity number just FYI.


Here is the trigger: 

trigger StandardQuoteRevisionNumTrigger on Quote (before insert) {
    List<Id> oppys = new List<Id>();
    for (Quote quote : Trigger.new) {
        oppys.add(quote.Opportunity__c);
    }
    List<Quote> quotes = [SELECT Id, qrnum__c, Opportunity__c FROM Quote WHERE Opportunity__c IN :oppys];
    for (Quote quote : Trigger.new) {
        Double qrNum = 0;
        for (Quote quote2 : quotes) {
            if (quote2.Opportunity__c == quote.Opportunity__c) {
                qrNum++;
            }
        }
        quote.qrnum__c = qrNum+1;
    }

    for (Integer i = Trigger.new.size()-1; i>-1; i--) {
        Quote quoteA = Trigger.new[i];
        for (Integer j = i-1; j>-1; j--) {
            Quote quoteB = Trigger.new[j];
            if (quoteA.Opportunity__c == quoteB.Opportunity__c) {
                quoteA.qrnum__c = quoteA.qrnum__c + 1;
            }
        }
    }
}
Nikki Hagen 3Nikki Hagen 3
Thanks for the help.  I was able to figure it out and it is working wonderfully!
Cyrus TalladenCyrus Talladen
Glad you fixed it!  Did it have something to do with the fact that the opportunity Id was only 7 digits long?

Cyrus T
www.levementum.com
Nikki Hagen 3Nikki Hagen 3
I believe so.  I changed this:
 
List<Id> oppys = new List<Id>();

to

List<string> oppys = new List<string>();

and that did the trick!  Pretty excited that I was able to accomplish this!  Thanks again for your tip!  It helped get me 90 % there!  I really appreciate it!  
 
Cyrus TalladenCyrus Talladen
Great! Keep it up and thanks for the like