Following the documentation on navigation with the sforce.one object, I'm attempting to create Opportunity Products with a link on a Visualforce page that has been added to the page layout and is visible in the Details section of the Lightning Experience view of the Opportunity. I'm calling:


When clicking "Add Product" from the standard Lightning Experience interface, the "Opportunity" value on the lightbox form is pre-populated.

However, calling sforce.one.createRecord('OpportunityLineItem'); results in a blank "Opportunity" value and clicking in the Product textbox results in an error.

createRecord Add Product

Clearly, calling sforce.one.createRecord('OpportunityLineItem'); isn't providing the Opportunity ID to the Add Product form, but I haven't been able to find any documentation or discussion of how to make this work.

I did find a known issue (my reputation is too low to post two links, but it's issue id=a1p3A00000186xfQAA) with Salesforce, that looks like a similar problem.

I know I can create a Visualforce page of my own for adding products, but I'd rather leverage the "Add Product" functionality that already exists in Lightning Experience, if possible. Am I missing something, or are there any pointers you'd recommend?

Here are the steps to reproduce the issue:

  1. Create the following Visualforce page and enable "Available for Salesforce mobile apps and Lightning Pages"

    <apex:page standardController="Opportunity"> 
      <script type="text/javascript"> 
          function createOLI() { 
      <div onclick="createOLI();">Create OpportunityLineItem</div> 
  2. Add the new Visualforce page to the Opportunity Page Layout

  3. View an Opportunity
  4. Click "Create OpportunityLineItem"

You'll see the "Create Opportunity Product" lightbox, but the Opp ID isn't passed in.

  • Can you please post your code here, so we can give a shot Jan 3, 2017 at 23:35
  • Thanks for giving this a shot, @santanu-boral. I've added the steps to reproduce the issue above.
    – Philip F
    Jan 11, 2017 at 22:52

1 Answer 1


This was likely not possible at the time this question was asked. It seems partly possible now, but still very buggy.


Before Summer'17 it was not possible to prepopulate fields. If the observation stated above was correct (I can't verify this anymore), it was not even possible to populate the fields manually. The prepopulation feature was added then and now you can do this:

    OpportunityId : "0060Y000007uaVI", 

But the Product field is still readonly, you can't pick the product and you can't save it. It looks like this and gives you only an ugly error message:

enter image description here

Now if you know already the PricebookEntryId you are going to use, you can prepopulate this too:

    OpportunityId : "0060Y000007uaVI", 
    PricebookEntryId: "01u0Y000001R5ro", 

On the UI the product field still is blank and readonly but at least the record gets saved.

Caution 1:

The this feature from Summer'17 works only if you put your Visualforce Page to API v40.0 or higher.

Caution 2:

Objectnames and Fieldnames are CASE-SENSITiVE! So opportunitylineItem is not OpportunityLineItem and only OpportunityLineItem is correct

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .