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
NecroGigglesNecroGiggles 

Custom shopping cart page apex code problem

I am trying to edit this code so when I add a product it will add 2 custom fileds to the opprtuinty line item. " A formula field on Price book entery "Type_c" =Text (Product2.Product_Type__c) and a check box "Needs_Approval__c"  I can't seem to get it added with out an error.  

public void addToShoppingCart(){
    
        // This function runs when a user hits "select" button next to a product
    
        for(PricebookEntry d : AvailableProducts){
            if((String)d.Id==toSelect){
                shoppingCart.add(new opportunityLineItem(OpportunityId=theOpp.Id, PriceBookEntry=d, PriceBookEntryId=d.Id, UnitPrice=d.UnitPrice, ));
                break;
            }
        }
        
        updateAvailableList();  
    }
Best Answer chosen by NecroGiggles
Sagar PareekSagar Pareek
Its clear from your code that field test__c is not present on PricebookEntry.Make sure  field test__c is present on PricebookEntry.

All Answers

NecroGigglesNecroGiggles
The error code I get is "Error: Compile Error: Invalid field initializer: PricebookEntry.test_c at line 137 column 147"
Shaijan ThomasShaijan Thomas
can you check PriceBookEntry field is available in opportunityLineItem?
Shaijan
Sagar PareekSagar Pareek
Its clear from your code that field test__c is not present on PricebookEntry.Make sure  field test__c is present on PricebookEntry.
This was selected as the best answer