0

Here's what I'm trying to do.

  • Select Cases Where Status = New.
  • Read the multiline Description field.
  • Add the Case Id, Subject, Description to the database requests table.
  • Depending on the Description
    • If it contains Port - Yes then Add Yes or true to the Port field in the db and add the Port Number to the Port Number field.
    • If it contains New - Yes then Add Yes or true to the New field in the db and add the New Number to the New Number field.

Here's my code.

    public async Task<IHttpActionResult> Get()
    {
        var client = await SalesforceService.GetUserNamePasswordForceClientAsync();

        var accounts = await client.QueryAsync<Case>("SELECT Id, Subject, Description FROM Case Where Status='New'");
        var sfAccounts = accounts.Records.Select(c => new
        {
            c.Id,
            c.Subject,
            c.Description
        });

        var request = new Request();
        List<Request> requestresults = new List<Request>();

        foreach (var c in sfAccounts)
        {
            if (c.Description != null)
            {
                using (StringReader sr = new StringReader(c.Description))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        //s.Split('-');
                        if (line.StartsWith("Port"))
                        {
                            request.Port = line;
                            requestresults.Add(request);
                        } 
                    }
                }
            }
        }
        return Ok(requestresults);

Although the requestresults contains two records only one is being returned. My Request Class

public class Request
{
    [Key]
    [Display(Name = "Contact ID")]
    [Createable(false), Updateable(false)]
    public string Id { get; set; }
    public string Port { get; set; }
    public string PortNumber { get; set; }
    public string New { get; set; }
    public string NewNumber { get; set; }

}

Sample Description - Each field is on a new line
Port - Yes /n
Number - 9781234567 /n
New - Yes /n
New Number - 9786543210

  • whats the issue you are facing? what specific thing you are looking for from community members? – Santanu Boral Jun 28 '17 at 3:57
  • My first question is why is the requestresults returning only one case when there are two cases when I go into it while debugging. Here are the results. [{"$id":"1","Id":null,"Port":"Port - Yes","PortNumber":null,"New":null,"NewNumber":null},{"$ref":"1"}] – Laura Bejjani Jun 28 '17 at 4:12
  • @LauraBejjani Are you saying that the size of accounts doesn't match sfAccounts when debugging? Are you debugging it as the same Salesforce user? – Daniel Ballinger Jun 29 '17 at 7:50
  • @DanielBallinger - I'm saying the return Ok(requestresults) should be returning 2 records (cases). It contains two cases. The count is 2 but it's only printing one. – Laura Bejjani Jun 30 '17 at 3:11
  • @DanielBallinger - It's only returning the last case. – Laura Bejjani Jun 30 '17 at 3:31

Your Answer

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

Browse other questions tagged or ask your own question.