1

I tried calling readMetadata method to retrieve FLowDefinition metadata. I ran below code:

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
System.debug('@@@ metadata service created');

MetadataService.FlowDefinition flow =
            (MetadataService.FlowDefinition) service.readMetadata('FlowDefinition',
                new String[] { 'NewFlow' }).getRecords()[0];
System.debug('name: ' + flow.fullName);
System.debug('activeVersionNumber: ' + flow.activeVersionNumber);
System.debug('masterLabel ' + flow.masterLabel);

But all the debug return "null" value. Can we not get FlowDefinition data using Metadata API?

2 Answers 2

1

Looks like there is something wrong with the Metadata API here.

I did a retrieve for the following package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>*</members>
        <name>FlowDefinition</name>
    </types>
    <version>38.0</version>
</Package>

In my dev org I got a package back with that contained a flowDefinitions for 4 flows.

  • flowDefinitions\LeadTest.flowDefinition
  • flowDefinitions\New_Customer_Flow.flowDefinition
  • flowDefinitions\Test.flowDefinition
  • flowDefinitions\UpdateContactAddressFromAccount.flowDefinition

If I try and do a readMetadata using these names I get a Metadata record back for reach flow.

SalesforceSession salesforceSession = \\...
MetadataServiceWrapper metadataService = salesforceSession.GetMetadataService();
SalesforceMetadata.Metadata[] md = metadataService.readMetadata("FlowDefinition", new String[] { "LeadTest", "Test", "LeadTest", "UpdateContactAddressFromAccount"});
foreach (SalesforceMetadata.Metadata m in md)
{
     if(m != null)
     {
          FlowDefinition flow = (FlowDefinition)m;
     }
}

While this returns a Metadata for each requested fullName, there isn't any data in them. Just a null fullName field.

Stepping down a level we can try it with the raw SOAP request

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:met="http://soap.sforce.com/2006/04/metadata">
   <soapenv:Header>
      <met:SessionHeader>
         <met:sessionId>00D700000000001!AQoAQFIx5ZioX_NotARealSessionId_HmH8aIn9Qpw</met:sessionId>
      </met:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <met:readMetadata>
         <met:type>FlowDefinition</met:type>
         <!--Zero or more repetitions:-->
         <met:fullNames>LeadTest</met:fullNames>
         <met:fullNames>Test.flowDefinition</met:fullNames>
      </met:readMetadata>
   </soapenv:Body>
</soapenv:Envelope>

Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <readMetadataResponse>
         <result>
            <records xsi:nil="true"/>
            <records xsi:nil="true"/>
         </result>
      </readMetadataResponse>
   </soapenv:Body>
</soapenv:Envelope>

Well, that isn't going to work. You get a nill <records xsi:nil="true"/> back for every full name you ask for. It doesn't actually matter if the fullName you provide corresponds to a valid flow or not.

One thing I found was that I needed to include dev orgs namespace prefix.

E.g.

Request

<met:readMetadata>
     <met:type>FlowDefinition</met:type>
     <met:fullNames>DFB__LeadTest</met:fullNames>
</met:readMetadata>

Response

<records xsi:type="FlowDefinition">
    <fullName>DFB__LeadTest</fullName>
</records>

So now I get the response back in the correct type, but no data other than the fullName that I passed in.

I double checked the FlowDefiniton.FullName via the Tooling API. I've got the names right with the namespace prefix. The Metadata API readMetadata just won't return any data. Varying the API version back several versions doesn't seem to help.

3
  • Thanks Daniel, So we can not get active version of the flow. Commented Dec 2, 2016 at 5:42
  • Like a flow can have many versions but there is only one active version, is there any way to retrieve that active flow in apex? Commented Dec 2, 2016 at 5:44
  • @FakehaQuazi I'd probably go with the ToolingAPI FlowDefinition to find the active flow using the ActiveVersionId field. That seems to return fine for me. Commented Dec 2, 2016 at 8:41
0

Using Metadata API version 38.0 you can.

These lines downloaded the active version information for my flow:

mConn = new MetadataPortTypeClient("SoapEndPoint", loginResult.metadataServerUrl);
...
...    
readMetadataRequest r = new readMetadataRequest(metadataHeader, null, "FlowDefinition", new string[] { "ChangeProgressFlow" });
readMetadataResponse rs = mConn.readMetadata(r);

If I fetch (retrieve package) the FlowDefinition for my flow, the XML is (the same information I got using readMetadata):

<?xml version="1.0" encoding="UTF-8"?>
<FlowDefinition xmlns="http://soap.sforce.com/2006/04/metadata">
    <activeVersionNumber>6</activeVersionNumber>
</FlowDefinition>

My flow has 6 versions:

enter image description here

I can fetch the content of each one but the active one (the first in the list).

If I try to get the XML of the active one, the error is:

Entity of type 'Flow' named 'ChangeProgressFlow' cannot be found

To get the content of the active one, my guess is that you have to append "-VERSION" to the name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .