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
NewGirlNewGirl 

Need Help with a simple trigger...

 

I am trying to update opportunitylineitem quantity when the productcode equals a certain value.
I wrote the below trigger as a first pass before I put in more detailed code.  
I am receiving a compile error :
Compile Error: Invalid field productid for SObject OpportunityLineItem at line 10 column 86
I highlighted the field that is in question in red.
thanks for ANY help!!!!
trigger convertproductqty on OpportunityLineItem (before insert, before update) {
     
 // string ProdCode;
 
 Opportunitylineitem[] OppLI = Trigger.new; 
    
 for(OpportunityLineItem s:OppLI){
     if (s.productid != null)
       {
       string prodcode = [select productcode from pricebookentry where product2id = :s.productid].productid;
       if (prodcode == 'AMS300')
           {
           s.quantity = 999;
           }
       }
    }
 }

 

agum34agum34

Check the API Docs for information on standard object fields -

 

http://www.salesforce.com/us/developer/docs/api/index.htm

 

"ID of the associated Product object. This field is unavailable as of version 3.0 and is only provided for backward compatibility. The Product object is unavailable beginning with version 8.0. Use the PricebookEntryId field instead, specifying the ID of the PricebookEntry object."

Ritesh AswaneyRitesh Aswaney

 

trigger convertproductqty on OpportunityLineItem (before insert, before update) {
 
Set<Id> priceBookEntriesSet = new Set<Id>{};
      
for(OpportunityLineItem s: Trigger.new)
priceBookEntriesSet.add(s.PriceBookEntryId);
Map<Id, PriceBookEntry>pbMap= new Map<Id, PriceBookEntry>([select Id, Product2.productcode from pricebookentry where id in :priceBookEntriesSet]);
for(OpportunityLineItem s: Trigger.new) {
   string prodcode = pbMap.get(s.PriceBookEntryId).Product2.ProductCode;
       if (prodcode == 'AMS300')
           s.quantity = 999;
           
       }
    
 }