0

Example for creating an Opportunity :

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Opportunity/ -H "Authorization: Bearer token" -H "Content-Type: application/json" -d @newrecord.json -X PATCH

Example request body newrecord.json file :

{ "Name":"FFNEw","CloseDate":"2015-05-02","StageName":"Prospecting","Probability":10 }

My ASP.net code :

using (WebClient client = new WebClient())
{
client.Headers.Add("Authorization", "Bearer " + token.access_token); client.Headers.Add("Content-Type", "application/json");
var request = (HttpWebRequest)(HttpWebRequest.Create(token.instance_url + "/services/data/v20.0/sobjects/Opportunity/"));
request.Method = "POST";
using (var requestWriter = new StreamWriter(request.GetRequestStream()))
{
  requestWriter.Write(json);
  requestWriter.Flush();
  requestWriter.Close();
}
var response = request.GetResponse();
}

I am able to create a single opportunity using above code. But when i try to create multiple record using below "newrecord.json" file getting error.

Example request body for multiple record newrecord.json file :

[{"Name":"Opp1","CloseDate":"2015-05-02","StageName":"Stage1","Probability":"10","Amount":"1500"},{"Name":"Opp2","CloseDate":"2015-02-03","StageName":"Stage2","Probability":"5","Amount":"2000"}]

Error in .net Code : 400 bad request

Error in Workbench : errorCode: METHOD_NOT_ALLOWED message: HTTP Method 'POST' not allowed. Allowed are HEAD,GET

2

The REST API doesn't provide a mechanism for updating multiple records simultaneously, like the Bulk or SOAP APIs do. You have two basic options: Custom REST Services, or Bulk/SOAP API.

If you use the Bulk API, you can post the data and query for the results later. If you use the SOAP API, you can post hundreds of records at once and get a real-time response. Using the REST API, you'll have to create records one at a time.

  • How can i use Soap/Bulk Api in .net for creating opportunity? – Fenil Suthar Mar 9 '15 at 11:01
  • Can you write same above code for creating Opportunity record using SOAP/Bulk API? – Fenil Suthar Mar 9 '15 at 11:02
  • @FenilSuthar, You cant expect people to write code for you just like. Search on Google for samples and modify samples as per your requirement. – AtulRajguru9 Mar 9 '15 at 12:36
  • @FenilSuthar this is a good place to start your quest: salesforce.com/us/developer/docs/api_asynch/Content/… – Mark Pond May 20 '15 at 2:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.