You need to sign in to do that
Don't have an account?

POST Ajax method with Jquery to create new account contact and Opportunity
I am trying to create New Account, Then Contact and Opportunity that is assigned to that account . but use Post method, so have them all in one page. I dont wanna create any class, I know I can do Account using method as it follows, however I am not sure if I can do the samething to create new contact and opportunity since I need account ID. Ill put fields on the page to ask user to enter new information
function createSobjectRecord() { var accountInfo = { "Name": "Testing Jquery with Rest" }; var accountInfoJson = JSON.stringify(accountInfo); $j.ajax({ type: "POST", url: "/services/data/v35.0/sobjects/Account", headers: { 'Authorization': "OAuth " + sessionId, 'Content-Type': 'application/json' }, crossDomain: true, data: JSON.stringify(accountInfo), dataType: 'json', success: function(responseData, status, xhr) { console.log(responseData); }, error: function(request, status, error) { console.log(request.responseText); } });
You can use the SObject Tree resource to create nested records(https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_composite_sobject_tree_create.htm).
This will eliminate the round trips to the servers, allowing you to create all the records in one call. You'll want to read the documentation for more information.
The actual code will look very similar: Obviously, the data structure changes a bit (attributes, records), but it's not much more complicated than the multiple-trip pattern.
Hope this helps.
Kindly mark this as solved if it's resolved.
Thanks,
Nagendra