Using flows with Language I/O API Managed Package
This document describes a potential use case for the Language I/O API managed package: using a Salesforce flow to translate a case Subject to the current user language upon creation of the record.
The Language Detection and Translation methods are Invocable Methods. This means that you can use them in Automation processes such as Flows.
How it works
Creating a new flow
- Open Salesforce. Go to Setup > Flows > New Flow.
- Select "Record-Triggered flow" and click Create. The following screen opens:
(Click to enlarge)
- Select "Case" as the base object
- Set the flow to run when a case is created.
- No entry conditions are necessary.
- Optimize the flow for "Actions and Related Records". This allows you to use invocable methods.
- Check the "Include a Run Asynchronously path..." setting. The flow uses an asynchronous path to do API callouts for language detection and translation through the Language I/O API. This is because the detect and translate callouts are designed to run in real time in the managed package.
Detect Language
- Create a text variable to store the detected language.
- Add an apex action that calls the Detect Language invocable method from the Language I/O managed package. The method is called "Detect Locale" (api name: LIO__DetectionAPI). The action will be added on the Run Asynchronously branch.
- Click Done, then populate the required input and output parameters:
- namedCredential: the API name of the named credential used to make the callout to the Language I/O server.
- routableID: unique ID specific to the current detection callout. This can be the case ID for example.
- sContent: the text for which you want to detect the language, in this example, the case subject.
- sDetectedLanguage: the detected language, saved in the variable created in step 1.
Perform Translation
- Create a text variable to store the translated text.
- Add an apex action that calls the Translate invocable method from the Language I/O managed package. The method is called "Translate" (api name: LIO__TranslationAPI). The action will be added on the Run Asynchronously branch.
- Click Done, then populate the required input and output parameters:
- namedCredential: the API name of the named credential used to make the callout to the Language I/O server.
- routableID: unique ID specific to the current detection callout. This can be the case ID for example.
- sContent: the text that is translated. In this example, the case subject.
- sTargetLocale: the target language. In this example, the language of the current user.
- sSourceLocale: the language of the original text (source language) that was detected in the previous callout.
- sTranslation: the translation result.
Update case subject
- Add an "Update Triggering Record" action to the flow, on the "Run Asynchronously" branch:
(Click to enlarge)
- The current case record to update.
- Set the conditions so that the update only happens if a translation was performed.
- Update the case Subject with the translation that was saved in the variable defined in the "Perform Translation" step.
Note: Because the translation happens asynchronously, the result is not visible immediately after the case is created. You must refresh the page to see the translation.
Comments
0 comments
Please sign in to leave a comment.