我如何获得Salesforce中特定对象的所有批准流程名称

时间:2019-07-12 11:30:01

标签: salesforce salesforce-lightning

我必须编写查询以获取特定xyz__c自定义对象上的所有批准过程

从ProcessDefinition中选择名称

上面的查询显示了所有对象批准过程。但是我需要对特定对象进行特定的批准过程

1 个答案:

答案 0 :(得分:0)

TableEnumOrId字段是您需要查询的字段:

  

指定与批准过程相关的对象,例如客户或联系人。

因此

static Token GetToken(string Url, string UserName, string Password)
{
    var authenticationBytes = Encoding.ASCII.GetBytes(UserName + ":" + Password);
    Token Result = null;

    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authenticationBytes));
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        HttpResponseMessage message = client.GetAsync(Url + "token").Result;
        if (message.IsSuccessStatusCode)
        {
            var inter = message.Content.ReadAsStringAsync();
            Result = JsonConvert.DeserializeObject<Token>(inter.Result);
        }
        return Result;
    }
}

static string CallApi(string url, Token Token)
{
    ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
    using (var client = new HttpClient())
    {
        if (Token != null)
        {
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + Token.access_token);
        }
        var response = client.GetAsync(url).Result;
        return response.Content.ReadAsStringAsync().Result;
    }
}


public override void CreateNewOutputRows()
{

    var token = GetToken("http://test-tms.ifa.net/api/", "user", "password");

    var Data = CallApi("http://myserver/api/salescrm-meetings?expand=staff,firms,advisers&start_date=2018-07-11&end_date=2019-07-10", token);

    List<Event> Events = JsonConvert.DeserializeObject<List<Event>>(Data);

    foreach (Event Event in Events)
    {
        EventOutputBuffer.AddRow();
        EventOutputBuffer.ID = Event.ID;
        EventOutputBuffer.Title = Event.Title;
        EventOutputBuffer.Type = Event.Type;
        EventOutputBuffer.SubType = Event.SubType;
        EventOutputBuffer.StartDate = Event.Start;
        EventOutputBuffer.EndDate = Event.End;

        foreach (Staff StaffMember in Event.Staff)
        {
            StaffOutputBuffer.AddRow();
            StaffOutputBuffer.ID = Event.ID;
            StaffOutputBuffer.Name = StaffMember.UserName;
            StaffOutputBuffer.Role = StaffMember.Role;
        }


        foreach (Firm FirmMember in Event.Firms)
        {
            FirmOutputBuffer.AddRow();
            FirmOutputBuffer.ID = Event.ID;
            FirmOutputBuffer.IDRef = FirmMember.IDRef;
            FirmOutputBuffer.Name = FirmMember.Name;
        }


        if (Event.Advisers != null)
        {
            foreach (Adviser AdviserMember in Event.Advisers)
            {
                AdviserOutputBuffer.AddRow();
                AdviserOutputBuffer.ID = Event.ID;
                AdviserOutputBuffer.IDRef = AdviserMember.IDRef;
                AdviserOutputBuffer.Name = AdviserMember.Name;
            }

        }
    }
}

class Token
{
    public string access_token { get; set; }
}
class Event
{
    public int ID { get; set; }
    public string Type { get; set; }
    [JsonProperty(PropertyName = "sub-type")]
    public string SubType { get; set; }
    public string Title { get; set; }
    public DateTime Start { get; set; }
    public DateTime End { get; set; }
    public Collection<Staff> Staff { get; set; }
    public Collection<Firm> Firms { get; set; }
    public Collection<Adviser> Advisers { get; set; }

}

class Staff
{
    public int ID { get; set; }
    public string UserName { get; set; }
    public string Role { get; set; }
}

class Firm
{
    public int ID { get; set; }
    public string IDRef { get; set; }
    public string Name { get; set; }
}
class Adviser
{
    public int ID { get; set; }
    public string IDRef { get; set; }
    public string Name { get; set; }
}