sfdc-happy-soup icon indicating copy to clipboard operation
sfdc-happy-soup copied to clipboard

Email template in flow not being found

Open JeffKrakowski opened this issue 4 years ago • 15 comments
trafficstars

I want to see where an email template is used. I know it is used in a Flow, but it does not show up when I select "where is it used"

JeffKrakowski avatar May 10 '21 10:05 JeffKrakowski

@JeffKrakowski is the email template directly used in the flow? or is the flow using an email alert? if so, can you try searching where the email alert is used?

pgonzaleznetwork avatar May 10 '21 10:05 pgonzaleznetwork

The template is used in the flow by an apex action [image: image.png]

On Mon, May 10, 2021 at 1:16 PM Pablo Gonzalez @.***> wrote:

@JeffKrakowski https://github.com/JeffKrakowski is the email template directly used in the flow? or is the flow using an email alert? if so, can you try searching where the email alert is used?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pgonzaleznetwork/sfdc-happy-soup/issues/129#issuecomment-836514452, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFBBEKAUBJZOOCS3M2P375TTM6W7VANCNFSM44QZ2VUA .

JeffKrakowski avatar May 10 '21 11:05 JeffKrakowski

Hi @JeffKrakowski I'm unable to see the image. Could you please attach it?

pgonzaleznetwork avatar May 10 '21 12:05 pgonzaleznetwork

done

On Mon, May 10, 2021 at 3:43 PM Pablo Gonzalez @.***> wrote:

Hi @JeffKrakowski https://github.com/JeffKrakowski I'm unable to see the image. Could you please attach it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pgonzaleznetwork/sfdc-happy-soup/issues/129#issuecomment-836650620, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFBBEKFI2UXPMLM2KHJ57SLTM7IGNANCNFSM44QZ2VUA .

JeffKrakowski avatar May 10 '21 12:05 JeffKrakowski

I'm still unable to see it. You would have to log in to Github and attach it from there, as opposed to replying on the email.

pgonzaleznetwork avatar May 10 '21 12:05 pgonzaleznetwork

Screenshot 2021-05-10 154438

JeffKrakowski avatar May 10 '21 15:05 JeffKrakowski

done

On Mon, May 10, 2021 at 3:48 PM Pablo Gonzalez @.***> wrote:

I'm still unable to see it. You would have to log in to Github and attach it from there, as opposed to replying on the email.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pgonzaleznetwork/sfdc-happy-soup/issues/129#issuecomment-836658399, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFBBEKAJSNTPYE3VGH3NSW3TM7I3RANCNFSM44QZ2VUA .

JeffKrakowski avatar May 10 '21 15:05 JeffKrakowski

I think this relationship is not supported by the dependency API. I'll do some research to see how this metadata is stored in salesforce. Thanks for the feedback!

pgonzaleznetwork avatar May 10 '21 17:05 pgonzaleznetwork

@pgonzaleznetwork I looked into this and the data can be found via the tooling API

Example: /services/data/v51.0/tooling/sobjects/Flow/flowId

Will return the following: Screen Shot 2021-05-13 at 9 09 22 PM

The 'inputParameters' folder will hold each of the individual parameters as defined in the apex method. You can see in the screenshot provided that my test method is expecting a String that represents the email template unique name, and that value would be stored in the 'stringValue' field.

One note is that although in this particular scenario its possible to access the data, it may be challenging to implement this feature more broadly? The input parameters in the invocable apex method are going to be user defined which means you can't expect a consistent value (i.e. it could be unique name, template id, something else?). If you did want to implement something like this, you'd likely need to search for a subset of defined values (id, unique name) and return those if they are found in any of the 'actionCalls' returned.

Hope this helps!

brandonrwind avatar May 14 '21 02:05 brandonrwind

Thank you so much for looking into this for me Pablo. I tried several times to enter the URL for tooling but I keep getting the same error message I also am not clear how this will help search among all my flows, it seems like I need to open each flow and node individually.

https://jinternship.my.salesforce.com/services/data/v51.0/tooling/sobjects/Flow/3003V000000050S This XML file does not appear to have any style information associated with it. The document tree is shown below. <Errors> <Error> <errorCode>INVALID_SESSION_ID</errorCode> Session expired or invalid </Error> </Errors>

On Fri, May 14, 2021 at 5:18 AM Brandon Wind @.***> wrote:

@pgonzaleznetwork https://github.com/pgonzaleznetwork I looked into this and the data can be found via the tooling API

Example: /services/data/v51.0/tooling/sobjects/Flow/flowId

Will return the following: [image: Screen Shot 2021-05-13 at 9 09 22 PM] https://user-images.githubusercontent.com/6753707/118210190-bbabe780-b42f-11eb-91a8-5b18c999c499.png

The 'inputParameters' folder will hold each of the individual parameters as defined in the apex method. You can see in the screenshot provided that my test method is expecting a String that represents the email template unique name, and that value would be stored in the 'stringValue' field.

One note is that although in this particular scenario its possible to access the data, it may be challenging to implement this feature more broadly? The input parameters in the invocable apex method are going to be user defined which means you can't expect a consistent value (i.e. it could be unique name, template id, something else?). If you did want to implement something like this, you'd likely need to search for a subset of defined values (id, unique name) and return those if they are found in any of the 'actionCalls' returned.

Hope this helps!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pgonzaleznetwork/sfdc-happy-soup/issues/129#issuecomment-840960542, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFBBEKGSYW5MZ5ZZXTDUCC3TNSB6LANCNFSM44QZ2VUA .

JeffKrakowski avatar May 14 '21 07:05 JeffKrakowski

@JeffKrakowski that comment wasn't for you, it was from @brandonrwind to me as he's helping me figure out how we can support your use case :) There's nothing for you to do at this stage and you are right, following the above steps is no different from opening each flow one by one.

@brandonrwind This is excellent research, thank you so much! is the apex email action user defined as in, do I have to create an apex class for this or does salesforce provide this out of the box? Did you have to create a class to get this to work?

Also, good to see that the metadata is available. However, a big challenge is that the Metadata property in the Flow object is only available if you query one flow at a time. If an org has 100 flows and only 1 uses an email action, I'd have to issue 100 SOQL queries to the tooling API just to find that one flow. That's way too many API calls.

This is the same problem I'm facing on #131 i.e the FlexiPage metadata is only available if you query it one by one.

I think long term I'm going to have to create a way to ask the user if they want HappySoup to cache some extra objects on the server side to improve the impact analysis capabilities. Then any subsequent request would use that cache to inspect those special metadata types.

@JeffKrakowski long story short this will be possible in the future, but it's long term.

pgonzaleznetwork avatar May 14 '21 08:05 pgonzaleznetwork

@brandonrwind one more thing, could you please research if we can use this url /services/data/v51.0/tooling/sobjects/Flow/flowId on the Composite Endpoint for the Tooling API?

https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_resources_composite_composite.htm

As per the docs

The following resources support composite.
All sObject resources (vXX.X/tooling/sobjects/)
The Query resource (vXX.X/tooling/query/?q=soql)

So maybe it would be possible to pass this URL multiple times (one per flow) as a composite request so that we don't have to issue multiple API calls.

We should investigate what's the limit of URLs we can pass to the composite request.

pgonzaleznetwork avatar May 14 '21 08:05 pgonzaleznetwork

@brandonrwind This is excellent research, thank you so much! is the apex email action user defined as in, do I have to create an apex class for this or does salesforce provide this out of the box? Did you have to create a class to get this to work?

Yes, you have to create an Apex Class with a method annotated with @InvocableMethod in order for it to be visible as an apex action within Flow.

Also, good to see that the metadata is available. However, a big challenge is that the Metadata property in the Flow object is only available if you query one flow at a time. If an org has 100 flows and only 1 uses an email action, I'd have to issue 100 SOQL queries to the tooling API just to find that one flow. That's way too many API calls. This is the same problem I'm facing on #131 i.e the FlexiPage metadata is only available if you query it one by one.

This is correct.

brandonrwind avatar May 14 '21 16:05 brandonrwind

@brandonrwind one more thing, could you please research if we can use this url /services/data/v51.0/tooling/sobjects/Flow/flowId on the Composite Endpoint for the Tooling API? So maybe it would be possible to pass this URL multiple times (one per flow) as a composite request so that we don't have to issue multiple API calls.

I can confirm this works as you described. You can combine multiple calls as subrequests by sending a POST to the composite endpoint like this: /services/data/v51.0/tooling/composite

and a sample request body like this: { "allOrNone":false, "compositeRequest" : [{ "method" : "GET", "url" : "/services/data/v51.0/tooling/sobjects/Flow/firstFlowId", "referenceId" : "refFlow" },{ "method" : "GET", "url" : "/services/data/v51.0/tooling/sobjects/Flow/secondFlowId", "referenceId" : "refFlow2" }] }

We should investigate what's the limit of URLs we can pass to the composite request.

According to documentation you can have 25 subrequests per call so this would help cut the number of total calls pretty significantly.

brandonrwind avatar May 14 '21 16:05 brandonrwind

We'll implement this feature once support for composite requests is implemented https://github.com/pgonzaleznetwork/sfdc-happy-api/issues/1

pgonzaleznetwork avatar May 17 '21 10:05 pgonzaleznetwork