• John Broaddus
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I'm having issue creating a task via REST API and need some help as to point out what I may be doing wrong. My code is the following:

public class SalesForceEvent
{
    public SalesForceAccount Account { get; set; }
    public string Id { get; set; }
    public string AccountId { get; set; }
    public string OwnerId { get; set; }
    public string Subject { get; set; }
    public string Type { get; set; }
    public string Description { get; set; }
    public string Status { get; set; }
    public string ActivityDate { get; set; }
    public bool IsClosed { get; set; }
    public bool IsDeleted { get; set; }
    public string Priority { get; set; }
    public string WhoId { get; set; }
    public string WhatId { get; set; }

}

var uri = serviceUrl + "/services/data/v20.0/sobjects/Account/task/";

var task = new SalesForceEvent();
task.OwnerId = "XXXXXXXXX";
task.Account = acct;
task.ActivityDate = DateTime.Now.ToString();
task.Subject = "Call";
task.Type = "Call";
task.Status = "Completed";
task.Description = " A Call for this new task";
task.IsClosed = true;
task.Priority = "Normal";
task.WhoId = "";
task.WhatId = "XXXXXXXXX";


var ser = new JavaScriptSerializer();
var body = ser.Serialize(task);

var req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
req.Headers.Add("Authorization: OAuth " + SFHelper.SalesForceToken.access_token);
req.ContentType = "application/json";
req.Method = "POST";

byte[] data = System.Text.Encoding.ASCII.GetBytes(body);
req.ContentLength = body.Length;
var os = req.GetRequestStream();
os.Write(data, 0, data.Length);
os.Close();

WebResponse resp;

try
{
    resp = req.GetResponse();
}
catch (WebException ex)
{
    resp = ex.Response;
}

if (resp != null)
{
    HtmlGenericControl hgc = new HtmlGenericControl();
    StringBuilder sb = new StringBuilder();

    System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
    sb.Append(sr.ReadToEnd().Trim());

    hgc.InnerHtml = sb.ToString();
    plcResults.Controls.Add(hgc);

}

When making the call I get the following error message:

[{"errorCode":"NOT_FOUND","message":"Provided external ID field does not exist or is not accessible: task"}]

Any assistance is greatly appreciated.
I'm having issue creating a task via REST API and need some help as to point out what I may be doing wrong. My code is the following:

public class SalesForceEvent
{
    public SalesForceAccount Account { get; set; }
    public string Id { get; set; }
    public string AccountId { get; set; }
    public string OwnerId { get; set; }
    public string Subject { get; set; }
    public string Type { get; set; }
    public string Description { get; set; }
    public string Status { get; set; }
    public string ActivityDate { get; set; }
    public bool IsClosed { get; set; }
    public bool IsDeleted { get; set; }
    public string Priority { get; set; }
    public string WhoId { get; set; }
    public string WhatId { get; set; }

}

var uri = serviceUrl + "/services/data/v20.0/sobjects/Account/task/";

var task = new SalesForceEvent();
task.OwnerId = "XXXXXXXXX";
task.Account = acct;
task.ActivityDate = DateTime.Now.ToString();
task.Subject = "Call";
task.Type = "Call";
task.Status = "Completed";
task.Description = " A Call for this new task";
task.IsClosed = true;
task.Priority = "Normal";
task.WhoId = "";
task.WhatId = "XXXXXXXXX";


var ser = new JavaScriptSerializer();
var body = ser.Serialize(task);

var req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
req.Headers.Add("Authorization: OAuth " + SFHelper.SalesForceToken.access_token);
req.ContentType = "application/json";
req.Method = "POST";

byte[] data = System.Text.Encoding.ASCII.GetBytes(body);
req.ContentLength = body.Length;
var os = req.GetRequestStream();
os.Write(data, 0, data.Length);
os.Close();

WebResponse resp;

try
{
    resp = req.GetResponse();
}
catch (WebException ex)
{
    resp = ex.Response;
}

if (resp != null)
{
    HtmlGenericControl hgc = new HtmlGenericControl();
    StringBuilder sb = new StringBuilder();

    System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
    sb.Append(sr.ReadToEnd().Trim());

    hgc.InnerHtml = sb.ToString();
    plcResults.Controls.Add(hgc);

}

When making the call I get the following error message:

[{"errorCode":"NOT_FOUND","message":"Provided external ID field does not exist or is not accessible: task"}]

Any assistance is greatly appreciated.