You need to sign in to do that
Don't have an account?
How to set Task subject, Name field, Related to field values in c#
I'm trying to create a salesforce task in c#. Succeeded in creating a task programatically but couldn't set the Subject, Name and Related To field values.
C# Code for setting field values
sObject newTask = new sObject();
sObject[] tasks = new sObject[1];
System.Xml.XmlElement[] taskElement = new System.Xml.XmlElement[6];
System.Xml.XmlDocument taskDocument = new System.Xml.XmlDocument();
taskElement[0] = taskDocument.CreateElement("Owner");
taskElement[0].InnerText = info.userFullName;
taskElement[1] = taskDocument.CreateElement("Status");
taskElement[1].InnerText = "Not Started";
taskElement[2] = taskDocument.CreateElement("Subject");
taskElement[2].InnerText = "Call";
taskElement[2].InnerXml = "Call";
taskElement[3] = taskDocument.CreateElement("Priority");
taskElement[3].InnerText = "Normal";
taskElement[4] = taskDocument.CreateElement("WhoId");
taskElement[4].InnerText = "003U0000003bY5UIAU"; //id of the Contact that is to be associated
taskElement[4].InnerXml = "003U0000003bY5UIAU";
taskElement[5] = taskDocument.CreateElement("WhatId");
taskElement[5].InnerText = "500U0000000rxp3IAA"; //id of the Case/Opportunity that is to be associated
askElement[5].InnerXml = "500U0000000rxp3IAA";
newTask.type = "Task";
tasks[0] = newTask;
SaveResult[] saveResult = service.create(tasks);
In CreateElement, I tried with "Subject" for subject field and "WhoId" for Contact field and "WhatId" for RelatedTo field but still no value is populated when the task is created. Any suggestion fixing this would be appreciated.
-Kayal
I don't see where you set the XmlElement array into the task, you need to add newTask.any = taskElement (at which point you should get an error about Owner, you want to set ownerId to the UserId of the owner)
All Answers
I don't see where you set the XmlElement array into the task, you need to add newTask.any = taskElement (at which point you should get an error about Owner, you want to set ownerId to the UserId of the owner)
Wow.. Din notice the blunder mistake. Thanks a lot Simon.