I keep getting this Uncaught ReferenceError: createLineItem is not defined for this line of code. It comes up in the console whenever I click on the "Create Line Item" button. I'm super uneducated with coding (slowly trying to learn) and I can't seem to figure out what the issue is.

Here is the code:

<apex:remoteObjects >
    <apex:remoteObjectModel name="Line_Items__c" fields="Id,Amount__c,Date_of_Transaction__c,Description__c,Individual_Account__c,P_Card_Expense__c,Stage__c,RecordTypeId"/>

<div class="mypage">
<input type="text" id="amount"/>
Date of Transaction:
<input type="date" id="date"/>
P-Card Expense?:
<input type="checkbox" id="pcard"/>
<input type="text" id="description"/>
<button onclick="createLineItem()">Create Line Item</button>

function createLineItem(){
    var LineItemAmount = document.getElementById("amount").value;
    var LineItemDate = document.getElementById("date").value;
    var LineItemPCard = document.getElementById("pcard").value;
    var LineItemDescription = document.getElementById("description").value;
    var LineItemRecordType = "012o0000000pnHd";
    var LineItemAccount = {!Individual_Account__c.Id};
    var LineItemStage = "Pending Hard Copy";
    var LineItem = new SObjectModel.LineItem();
LineItem.create({Amount__c: LineItemAmount}, function(error, records) {
    if (error) {
    } else {

Any help is appreciated!

  • Can you just remove <button onclick="createLineItem()">Create Line Item</button> and instead <input type="button" onclick="createLineItem()" value="Create Line Item"/> try once ?
    – Ratan Paul
    Mar 31, 2016 at 15:28

2 Answers 2


One reason the function definition is not completing (and so the function is not available when the click happens) is because of missing quotes - add them here:

var LineItemAccount = "{!Individual_Account__c.Id}";


var LineItemAccount = a085000000JJwBOAA1;

is not valid JavaScript but this (with quotes added) is valid:

var LineItemAccount = "a085000000JJwBOAA1";

Use your browser's "View Source" to see what is output by the Visualforce and check that it looks right. Also look in your browser's console for JavaScript errors. See e.g. How do I start to debug my own Visualforce/JavaScript?


Try removing the ; after the closing of the function createLineItem()

};(this one)


You must log in to answer this question.

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