I'm a newbie to salesforce and i want to create a custom Purchase Order record using CreateAsync method of Force.com Tool. I'm successfully able to create a record when i'm just passing the parameter value as string.

For e.g for a Campaign Creation :

var campRecord = new Campaign() { Name ="PickListCamp"};

The problem arises when i want to pass a pickup list value as a parameter in the CreateAsync method.

I'm getting the pickuplist values for say Status field of Purchase_Order object but when i pass the Pickup list value , i get an error saying :

"Cannot deserialize instance of picklist from START_OBJECT value { or request may be missing a required field salesforce c#}".

I'm using the following piece of code to get the picklist values from Status column of Campaign object :

string dcampQry = "Select DurableId From FieldDefinition where EntityDefinition.DeveloperName = 'Campaign' and DataType = 'Picklist' and DeveloperName = 'Status'";

var dcampResults = await client.QueryAsync<FieldDefination>(dcampQry);

var campDId = dcampResults.Records[0].DurableId;

string campQry = "SELECT DurableId, EntityParticleId, IsActive, IsDefaultValue, Label, ValidFor, Value  FROM PicklistValueInfo WHERE EntityParticleId = '" +campDId  + "'";

var campResults = await client.QueryAsync<Picklist>(campQry);

 Picklist campValue = campResults.Records[0];

After getting the pickuplist values, I'm passing the parameter as follows in the CreateAsync method :

var campRecord1 = new Campaign() { Name = "PickListCamp", Status = campValue };

var createdAccRecord1 = await client.CreateAsync("Campaign", campRecord1);

Can anyone help me out on how to create a record by passing a pickuplist value in CreateAsync method. I'd be really grateful.

  • Hi Srijesh, please include an example of the code you're using that doesn't work. I'm not a C# programmer, but it sounds like you're supplying the wrong type of value. – David Reed Feb 4 '19 at 14:14
  • Hi David, I have updated the post with sample code. Kindly help :) – srijesh nair Feb 4 '19 at 14:30

I am not a C# developer, so I cannot tell you exactly what to write in your code, but I think it's clear that the cause is here:

var campRecord1 = new Campaign() { Name = "PickListCamp", Status = campValue };

campValue is an instance of a Tooling API object (PicklistValueInfo), representing the metadata for a single Picklist entry.

When you populate a picklist field, you don't supply an object - you supply a string value, the API name of the picklist entry. Here, you want the property Value from campValue, which should be a String.

The error you're getting back is indicating that Salesforce is receiving an object in its inbound REST request where a scalar value is expected.

| improve this answer | |
  • Hi David,thank you for the response. Since the second parameter expects a pickuplist datatype,I passed campValue. If I pass the Value property ,how should I pass the second parameter? – srijesh nair Feb 4 '19 at 14:56
  • Srijesh, it's "picklist", not "pickuplist". A picklist value is a string, unless C# does something unusual with it. – David Reed Feb 4 '19 at 14:58
  • Okay David ,I'll try that out and let you know as soon as possible. thanks – srijesh nair Feb 4 '19 at 15:03
  • Hi David, var campRecord1 = new Campaign() { Name = "PickListCamp", ? = campValue.Value }; Could you please suggest as to what the field name should be as 'Status' is of datatype Picklist. I have defined the Campaign class as follows : private class Campaign { public const String SObjectTypeName = "Campaign"; public String Name { get; set; } public bool isActive { get; set; } public Picklist Status { get; set; } } – srijesh nair Feb 4 '19 at 16:13
  • The Status field on Campaign is not an object. It is a string value. You're using the same class to represent the Tooling API result and the Campaign field value, and that will not work. – David Reed Feb 4 '19 at 16:18

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.