I am facing an error using javascript remoting Salesforce, what should I do?
I am trying to call a custom apex controller from javascript code in my visual force page but keep getting the following error :
Visualforce Remoting Exception: No such column '_name' on sobject of type facture__cHere's the javascript call :
var createFacture = function() {
var facture = new Object Model.Facture();
var factureReferenceField = document.getElementById('facture-reference');
var factureClientField = document.getElementById('select-client');
facture.Reference__c = factureReferenceField.value ;
facture.Client _c = facture Client Field.value;
console.log(facture);
Visualforce.remoting.Manager.invokeAction(
//Invoking controller action getcon
'{!$RemoteAction.TestController.saveFacture}',
facture, facture Lines,
function(result, event){
console.log("in callback func");
console.log(event.status);
console.log(event.message);
},
{escape: true}
);
console.log('hell yeah');
}
and here's the apex controller method Im trying to call :
@RemoteAction
public static Facture _c save Facture(Facture _c facturé, Ligne _c[] lines) {
// Perform isUpdateable() checking first, then
System.debug('facture: '+ facture);
System.debug('lines: '+ lines);
upsert facture;
for(Ligne__c line : lines) {
line.facture _c = facture.Id;
upsert line;
}
return facture;
}
I ve made the full code of the page and the controller available on github if you need to see more : How to fix this error and make my remote call work?
Regarding the javascript remoting Salesforce - apex:remoteObjects provides a JS-only interface; you can use this to perform DML operations and queries without Apex.
For a remote action method, you'd use a simple object:
var facture = { };
...
facture.Reference__c = factureReferenceField.value;
facture.Client _c = facture Client Field.value;
Visualforce.remoting.Manager.invokeAction(
//Invoking controller action getcon
'{!$RemoteAction.TestController.saveFacture}',
facture, ...