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
EnryEnry 

Set Product for new opportunity lineitem

in a trigger i'am going to create a new opportunitylineitem for an opportunity:

 

 

                 OpportunityLineItem newOpptLineItem = new OpportunityLineItem();
                 newOpptLineItem.OpportunityId = opptInserted.Id;
                 newOpptLineItem.=cs.OppProductCpvId__c; // FOR GIGABYTE
                 newOpptLineItem.Quantity = 1;                   
                 newOpptLineItem.PricebookEntryId = peWEBinteractive.Id;
                 opptLineItemsToInsert.add(newOpptLineItem);  .

 

I want to set up a product for this new opportunitylineitem.

newOpptLineItem.ProductId isn't available.

Thanks in advantage for any advice.

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

ProductID - ID of the associated Product record. 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.

 

This field is not available.

 

newOpptLineItem.PricebookEntryId = peWEBinteractive.Id;

 

You have done this. this means the product of this pricebookentry will be automatically in the productid of Opportunitylineitem.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

All Answers

souvik9086souvik9086

ProductID - ID of the associated Product record. 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.

 

This field is not available.

 

newOpptLineItem.PricebookEntryId = peWEBinteractive.Id;

 

You have done this. this means the product of this pricebookentry will be automatically in the productid of Opportunitylineitem.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

This was selected as the best answer
EnryEnry

Thank you very much! how can i create a PriceBookEntry from user interface? after i will store the pricebook id in a custom setting.

Thanks again!

souvik9086souvik9086

Create a PriceBookEntry from user interface means? You want to select opportunity lookup in UI? You can create that and you can assign that pricebbookid in controller or you can choose that as well in Ui through input field.

 

If the post helps you please throw KUDOS.