You need to sign in to do that
Don't have an account?
konigswagger
CREATE new SObject using Javascript
I am using the Force.com-JavaScript-REST-Toolkit to access my data stored at Salesforce (using OAuth) in my Javascript applcation and was wondering how I would go about creating new records. I've seen many examples for creating SObjects and making the CREATE call in Java, but I am not sure how to do this in JS. Does anybody have a small snippet of code to show how to do this?
Hi konigswagger,
This is small code to create a Account record Using Javascript.
You can try querying, inserting, updating and many things which we usually perform in apex.
Hope it Helps..
does not seem to work despite following the specifications. Any tips? Should I include the __c?
Is there any way to not use APEX? I am using the Force.com toolkit and it includes a method called create as follows:
/*
* Creates a new record of the given type.
* @param objtype object type; e.g. "Account"
* @param fields an object containing initial field names and values for
* the record, e.g. {:Name "salesforce.com", :TickerSymbol
* "CRM"}
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
forcetk.Client.prototype.create = function(objtype, fields, callback, error) {
this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/'
, callback, error, "POST", JSON.stringify(fields));
}
);
My code:
client.create("FinAccount__c",
{
:currency 'cash_money',
},
function(response){
alert('success');
}
)
What error are you getting? And how are you getting aroud the same-domain policy?
Figured it out thanks :) The syntax in the documentation was wrong. The second parameter is just a JSON object.
Can you let me know where the error in the documentation is so I can get it fixed?
Thanks.
/*
* Creates a new record of the given type.
* @param objtype object type; e.g. "Account"
* @param fields an object containing initial field names and values for
* the record, e.g. {Name : "salesforce.com",
* TickerSymbol : "CRM"}
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
I changed the location of the colon and it now works.
Ah, this is the documentation for that specific JS toolkit. Thanks.