[SalesForce] Get all automations that exist using SOAP using C#

Goal: I'm attempting to get every automation in the system available to me under my account using the SOAP API in C#. It's also part of this guy's question. I know this has been asked but this is specifically my question about how to get every automation and not a three part question. If after you answer this you want to help him out, please do. That's why I've referenced his question in my post.

Setup: I have the WSDL (aka PartnerAPI) referenced under "Service References" in my C# class library project.*

What I've tried:
I've used a simplified version of the function suggested in the help documentation to retrieve them without any success. I've tried various combinations of rr.Properties with no success as it was an issue I had previously. I've even tried retrieving AutomationActivity and AutomationTask objects to try to help this guy using this simplified version of a request with no success.

public static void RetrieveAutomation(SoapClient soapClient)
{
    RetrieveRequest rr = new RetrieveRequest();
    rr.ObjectType = "Automation";

    rr.Properties = new string[] { "Name" };

    string sStatus = "";
    string sRequestId = "";
    APIObject[] rResults;

    sStatus = soapClient.Retrieve(rr, out sRequestId, out rResults);

    Console.WriteLine("Status: " + sStatus);
    Console.WriteLine("RequestID: " + sRequestId);

    foreach (Automation automation in rResults)
    {
        Console.WriteLine("Name: " + automation.Name);
    }
}

I've used the same simplified function with rr.ObjectType set to other types like folders, data extensions and user initiated send a.k.a the EmailSendDefinision.

* I've even compiled this class library and imported it as a "Plugin" into LinqPad and can run API calls on the fly.

How to do the above:
Make a new project, simplify the namespace to whatever you want, add the service reference url then compile. Put the dll produced into the plugins directory used by LinqPad and import the namespace whenever LinqPad detects it's not referenced. Real simple. If you have questions you can ask…as long as you realize this link is how.

Best Answer

I have coded it with the same result, but I have found some interesting thing, you can call Retrieve method filtering by "isActive" parameter and "true" value, and after repeat the call filtering by "isActive" parameter and "false" value, and you will have the full set result of automations. The only thing is that I have to do in Async mode because of .Net Core 2.1 version only shows me Async calls once I associate the WFC service.

My code working:

List<Automation> AutomationList = new List<Automation>();

RetrieveRequest rr = new RetrieveRequest();
rr.ObjectType = "Automation";
rr.Properties = new String[] { "Name", "Description", "CustomerKey", "IsActive" };

SimpleFilterPart sfp = new SimpleFilterPart();
sfp.SimpleOperator = SimpleOperators.equals;
sfp.Property = "IsActive";
sfp.Value = new String[] { "true" };
rr.Filter = sfp;

RetrieveResponse rResp = await soapClient.RetrieveAsync(new RetrieveRequest1(rr));

for (int i = 0; i < rResp.Results.Length; i++)
{ 
    AutomationList.Add((Automation) rResp.Results[i]);
}

sfp.Value = new String[] { "false" };
rr.Filter = sfp;

// Add inactive automations
rResp = await soapClient.RetrieveAsync(new RetrieveRequest1(rr));
for (int i = 0; i < rResp.Results.Length; i++)
{
    AutomationList.Add((Automation)rResp.Results[i]);
}

return AutomationList;

I hope it will be useful :)

Related Topic