• Bill Jones
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hello,

I am trying to push data from my C# app into Salesforce. In Salesforce, I have a custom object, called Product, with the following four custom fields:
Field Label     API Name                 Data Type
-----------     ---------                ------------------------
Category        Category__c              Master-Detail (Category)
Description     Product_Description__c   Long Text Area (32768)
Foreign ID      Foreign_ID__c            Text(255)
Status          Product_Status__c        Picklist
I am trying to create a record in my Product object via the REST API. Currently, I have the following:
When this code gets executed,
var product = new Product();
product.Category__c = "C-0000001";
product.Product_Description__c = "This is a test sent at " + DateTime.Now.ToString();
product.Product_Status__c = "Available";

var json = JsonConvert.SerializeObject(product);

var request = (HttpWebRequest)(HttpWebRequest.Create(instanceUrl + "/services/data/v20.0/sobjects/Product__c/"));
request.Method = "POST";
request.ContentType = "application/json";

request.Headers.Add("Authorization: OAuth " + accessToken);
using (var requestWriter = new StreamWriter(request.GetRequestStream()))
{
  requestWriter.Write(json);
  requestWriter.Flush();
  requestWriter.Close();
}

var response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
  var data = reader.ReadToEnd();
}
When this code gets executed, I get a 400 error. The error is:
73
[{"message":"Category: id value of incorrect type: C-0000001","errorCode":"MALFORMED_ID","fields":["Category__c"]}]
0
What am I doing wrong? I suspect this has to deal with the fact that Category is a Master-Detail. I'm guessing I'll have a similar issue with the Picklist value. However, I'm not sure how to define that in C# to pass to Salesforce via the REST API.  Thank you for any help you can provide.



 
Hello,

I'm new to Salesforce. I have a ASP.NET MVC app written in C# that I have authenticated with Salesforce via OAuth. I have authenticated with Salesforce via the "Obtaining an Access Token in a Web Application (Web Server Flow)" described here (https://developer.salesforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com). I have successfully received an access token. I am now trying to use that access token to create a record on an object in Salesforce. Currently, I have the following code:
// Build my object in C# and serialize it to JSON via JSON.NET
var myObject = new CustomObject();
myObject.ObjectId = 1;
myObject.Description = "This is a test sent at " + DateTime.Now.ToString();
var json = JsonConvert.SerializeObject(myObject);

// Send the data to Salesforce
var request = (HttpWebRequest)(HttpWebRequest.Create("https://na1.salesforce.com/services/data/v20.0/sobjects/MyObject/"));
request.Method = "POST";
request.ContentType = "application/json";

// Add the access token for authentication information
// The accessToken variable is passed into the method. I have verified that accessToken matches what is sent back during OAuth
request.Headers.Add("Authorization", "Bearer " + accessToken);

// Send the object to Salesforce
var response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
  var data = reader.ReadToEnd();
}

...

The code above attempts to pass my C# object to my Salesforce object via the API documentation (https://www.salesforce.com/us/developer/docs/api_rest/). I am relying on the "Using REST Resources -> Using REST API Resources -> Working with Records -> Create a Record" section. When the code executes, an exception is thrown. The exception is a 401 - Unauthorized error. This makes me thing that I'm passing the access token incorrectly. However, it looks correct to me.

Can someone please tell me what I'm doing wrong?

Thank you!
 
Hello,

I am building an app that will interact with the REST API. Currently, when I run the app locally and attempt to get the request token, I receive the following error:

59
error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration
0

How can I do local development against the REST API?
Hello,

I am new to Salesforce. I recently completed the Force.com Platform Fundamentals guide (An Introduction to Custom Application Development in the Cloud).

I know that I can pass data to a web service from Salesforce (this is shown in Chapter 11). However, everything I see relies on a trigger from the data or a user initiated action. My question is, in Salesforce, to call a web service on a given time interval? If so, how?

Thank you!
Hello,

I'm new to Salesforce. I have a ASP.NET MVC app written in C# that I have authenticated with Salesforce via OAuth. I have authenticated with Salesforce via the "Obtaining an Access Token in a Web Application (Web Server Flow)" described here (https://developer.salesforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com). I have successfully received an access token. I am now trying to use that access token to create a record on an object in Salesforce. Currently, I have the following code:
// Build my object in C# and serialize it to JSON via JSON.NET
var myObject = new CustomObject();
myObject.ObjectId = 1;
myObject.Description = "This is a test sent at " + DateTime.Now.ToString();
var json = JsonConvert.SerializeObject(myObject);

// Send the data to Salesforce
var request = (HttpWebRequest)(HttpWebRequest.Create("https://na1.salesforce.com/services/data/v20.0/sobjects/MyObject/"));
request.Method = "POST";
request.ContentType = "application/json";

// Add the access token for authentication information
// The accessToken variable is passed into the method. I have verified that accessToken matches what is sent back during OAuth
request.Headers.Add("Authorization", "Bearer " + accessToken);

// Send the object to Salesforce
var response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
  var data = reader.ReadToEnd();
}

...

The code above attempts to pass my C# object to my Salesforce object via the API documentation (https://www.salesforce.com/us/developer/docs/api_rest/). I am relying on the "Using REST Resources -> Using REST API Resources -> Working with Records -> Create a Record" section. When the code executes, an exception is thrown. The exception is a 401 - Unauthorized error. This makes me thing that I'm passing the access token incorrectly. However, it looks correct to me.

Can someone please tell me what I'm doing wrong?

Thank you!