I would like to create a VF page ("AllUnitIdssaved") that will accept users inputs. This VF page is on the "Shipment_Details__c", which has a lookup to "QuoteLineItem". When the user clicks a custom button ("Create Unit Id") on the Shipment_Details related list, it should bring up the VF page.

A couple things I need help on:

  1. I'm getting an error when I click the "Create Unit Id" button. Below is my setup for my custom button.

    Behavior: Display in existing window with sidebar
    Button or Link URL: window.location = '/apex/AllUnitIdssaved';

  2. How do I link the Shipment_Details records that are being created on the Visualforce page to the Quote Line Item records? Here's my markup:

    <apex:page Controller="AddmultipleUnitIdsController">
        <apex:form >
            <apex:pageBlock >
                <apex:pageBlockTable value="{!listUnitId}" var="unit">
                    <apex:column headerValue="Create Unit Id">
                        <apex:inputField value="{!unit.Name}"/>
                <apex:pageBlockButtons >
                    <apex:commandButton value="Create Unit Ids" action="{!addUnitId}"/>
                    <apex:commandButton value="Save Unit Ids" action="{!saveUnitId}"/>


    public class AddmultipleUnitIdsController {
        Shipment_Detail__c unitid = new Shipment_Detail__c();
        public list<Shipment_Detail__c> listUnitId{ get; set; }
        public AddmultipleUnitIdsController()
            listUnitId=new list<Shipment_Detail__c>();
        Public void addUnitId()
            Shipment_Detail__c unit = new Shipment_Detail__c();
        public PageReference saveUnitId() {
        for(Integer i=0; i<listUnitId.size(); i++)
            insert listUnitId;
            return Page.AllUnitIdssaved;
  • What's the error you're seeing when you click the Create Unit Id button? Commented Oct 4, 2018 at 23:00

1 Answer 1


As for linking the new Shipment_Detail records to their parent QuoteLineItem record, you need to pass the QuoteLineItem's Id to the visualforce page in the querystring, like this:


Then, in your page controller, you can get the Id value like this:

Id quoteLineItemId = apexPages.currentPage().getParameters().get('Id');

Use the Id to populate the lookup field for each new Shipment_Detail record.

Also, you should take your DML write out of the for loop. (This is a no-no!)

for(Integer i=0; i<listUnitId.size(); i++)
    insert listUnitId;

Since you can only have 150 DML operations (inserts, updates, deletes, ...) in a single transaction, you could easily use them all up if you inserted one record at a time!

Instead, you can insert your list of Shipment_Detail records all at once.


You must log in to answer this question.

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