+ Start a Discussion

Trigger body is invalid and failed recompilation?

We have serveral triggersdating back from the days before my time, many have been failing and with similar errors.
They all  has always worked and still worked, in Production and the other developer sandbox, but not the full sandbox which was recently refreshed. 

This is one of the failures i get when adding or editing an opportunity:
"Apex trigger UpdateOpportunityProduct caused an unexpected exception, contact your administrator: UpdateOpportunityProduct: execution of BeforeUpdate caused by: line 5, column 21: trigger body is invalid and failed recompilation: Variable does not exist: pricebookentryid"

and the code:
trigger UpdateOpportunityProduct on OpportunityLineItem (before insert, before update) {
	    Set<Id> pbeIds = new Set<Id>();
	    for (OpportunityLineItem oli : Trigger.new) 
	    Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>([select Product2.Product_Type__c, Product2.Product_Category__c, Product2.ProductCode, Product2.Assessment__c, Product2.PD_Complimentary_Group_Type__c from PricebookEntry where id in :pbeIds]);
	    for (OpportunityLineItem oli: Trigger.new) {
	        Product2 product = entries.get(oli.PricebookEntryId).Product2;
	        oli.Product_Type__c = product.Product_Type__c;

Already reach out to salesforce and closed my ticketet saying it's "Internal Server Error", let me know what you guys think?

Best Answer chosen by MC2014
I've solved it, I just refresh the sandbox and everything is back to normal.

All Answers

did u check the permissions, i think it's the access issue.
I'm assigned the system administrator profile.
make sure the related PriceBook record is active?
Yes their active, even if they weren't i'm sure I wouldn't be able to add those product or they will produced a different apex error.
try to update the version of trigger and see.
Nope that not either, because similar failure in another trigger which is verison 30.0.

Do you think it's that their salesforce platform is screwed up after I refresh the sandbox around 6/16? that is when I notice this started happening.
hmm, if its only happening in that one sandbox, i dont think we can do anything about it from our side, its the salesforce issue.

Vishant ShahVishant Shah
is your sandbox on CS7, my sandbox on CS7 has started to have issues since summer 14 release. i raised a case with SFDC and because we a non profit they dont support us as much. There is something on pricebook that has changed that is causing my tests to fail as well.


my sandbox is CS1, yes, it seems that after the refresh error is showing up and salesforce support just redirected me to this post : "http://salesforce.stackexchange.com/questions/1662/unexpected-error-occured-compiling-apex-class"
  1. After going through the the steps "setup-->develop-->apex classes and click the "compile all classes"

    The errors messages I get from my full sandbox and  my deverloper and box are completely different. Shoudn't they have similar error messages since they pretty much contain the same apex class and triggers as production.
  2. The error from the trigger is telling me that PricebookEntryId doesn't exist. Isn't that a standard field in OpportunityLineItem?

    So I am looking at "https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_opportunitylineitem.htm" and it says "Exists only for those organizations that have Products enabled as a feature." so, how do I check to see if it's enabled?

I've solved it, I just refresh the sandbox and everything is back to normal.

This was selected as the best answer