This article will show you how to output files using Office File Creator and update Opportunity records in Salesforce Flow. Office File Creator can be integrated into the Screen Flow.
*This procedure is for Office File Creator Ver. 2.xx. If you are using Ver. 1.xx, please refer to Output files and update Opportunity records in Salesforce Flow (for OFC Ver.1) – Office File Creator Advanced –.
Completed Flow
By clicking on the "Output Invoice" button, a pop-up window will appear, and when the flow is executed, output files and update the field "Bill Output Date".
Demo
Key Points for Flow Creation
- The parameter that receives the record Id from the records screen in the flow is "recordId". Create a text type variable "recordId" in the flow. No other variable name can receive the record Id.
- To output a file in Office File Creator, place the ofcForFlowScreen component in the screen flow. It returns the result of creating the files (success or failure) and returns an error message in case of failure.
- For details on the parameters and return values of the ofcForFlowScreen component, refer to the Instruction manual.
Flow Process Overview
This is the overall picture of the flow.
1. Top Screen
Display the confirmation message.
Place ofcForFlowScreen component in the screen flow and output the file.
2. OFC error judgment
Judge the success or error of the output result. In case of success, go to process 3. In case of error, go to process 2e.
2e. Error Screen
Displays an error message and end the flow.
3. Update Bill Output Date
Update the Bill Output Date of the Opportunity.
4. Completion Screen
Display the completion message.
Create the Flow
Let's create the flow. Open Flows from Setup and click the "New Flow" button.
Select "Screen Flow" and click the "Create" button.
Create recordId Variable
Click the "Toggle Toolbox" button in the upper left corner of the screen, then click the "New Resource" button.
Create the Record Id variable. After setting, click the "Done" button.
Resource Type: Variable
API Name: recordId
Data Type: Text
Available for input: check on
Note: recordId is a variable that receives the record Id from the record screen. Be sure to use "recordId" (only "I" is capitalized). Other variable names cannot receive the record Id.
First, save the flow. Click the "Save" button.
Save the Flow under any name. Here it is saved as follows.
Flow Label: Output Invoice Screen Flow
Flow API Name: OutputInvoiceScreenFlow
If a warning message appears, close it with an "X".
1. Top Screen
Click the "+" mark under Screen Flow.
*Place the cursor over the "○" mark and the "+" mark (add element) will appear.
Select "Screen".
Set Screen properties.
Label: Top Screen
API Name: Top_Screen
Show Footer: check off
Click "Display Text" in the left component and set the properties.
API Name: dispConfirmMsg
Text: Are you sure you want to output the invoice?
Click "ofcForFlowScreen" in the left component and set the properties. After setting, click the "Done" button.
API Name: OFC
recordId: {!recordId}
save: Empty *To save the file, enter "file" or "att".
template: OpportunityInvoice *Enter the Template Api Name of the OFC_Template record.
Note: Select the variable {!recordId} from the candidate resources. In the same manner thereafter, settings of the form {!xxx} will be selected from the resources.
2. OFC error judgment
Click the "+" mark under Top Screen and select "Decision".
Sets the properties of the Decision.
Label: OFC has errors?
API Name: DecOFCError
[OUTCOME DETAILS] section
Label: Error
Outcome API Name: decOFCError_Yes
Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
Recourse: {!OFC.isSuccess}
Operator: Equals
Value: {!$GlobalConstant.False}
Click "Default Outcome" in the left sidebar.
Set the properties of OUTCOME DETAILS, and Click the "Done" button.
[OUTCOME DETAILS] section
Label: Success
2e. Error Screen
Click the "+" mark under Error and select "Screen".
Set Screen properties.
Label: Error Screen
API Name: Error_Screen
Click "Display Text" in the left component and set the properties. After setting, click the "Done" button.
API Name: dispErrorMsg
Text: {!OFC.errorMessage}
*Set text color to red from the color palette.
*Select "errorMessages", not "errorMessages". "errorMessages" is the return value when outputting multiple files at once.
Click the "+" mark under Error Screen and select "End".
It is branched into two.
3. Update Invoice Output Date
Click the "+" mark under Success and select "Update Records".
Set the properties.
Label: Update Bill Output Date
API Name: UpdateBillOutputDate
How to Find Records to Update and Set Their Values: check on "Specify conditions to identify records, and set fields individually"
[Update Records of This Object Type] section
Object: Opportunity
[Filter Opportunity Records] section
Condition Requirements to Update Records: All Conditions Are Met (AND)
Field: Id
Operator: Equals
Value: {!recordId}
[Set Field Values for the Opportunity Records] section
Field: BillOutputDate__c
Value: {!$Flow.CurrentDate}
*A custom fields named Bill Output Date (API Name: BillOutputDate__c) is created in Opportunity.
After setting, close the properties screen by clicking the "X" button in the upper right corner of the screen.
Click the "Save" button as appropriate to save your edits.
4. Completion screen
Click the "+" mark under Update Invoice Output Date and Select "Screen".
Set Screen properties.
Label: Completion Screen
API Name: Completion_Screen
Click "Display Text" in the left component and set the properties. After setting, click the "Done" button.
API Name: dispCompleteMsg
Text: Completed.
Flow creation is complete.
Click the "Save" button.
Debug the Flow
Click the "Debug" button.
Enter the record Id and click the "Run" button. Enter the Opportunity record Id here.
The debug screen will appear. Click the "Next" button.
Confirm that the file is output.
Confirm the date is set to the Bill Output Date in the Opportunity record screen.
Click the "Activate" button on the flow. Close the Flow screen.
Create Custom Button
Create a custom button for outputting files to be placed on the record screen.
Open the target object from the Object Manager in Setup. Click "Buttons, Links, and Actions" in the left sidebar, then click the "New Action" button.
Set the Action Information. After setting, click the "Save" button.
Action Type: Flow
Flow: Output Invoice Screen Flow
Label: Output Invoice
Name: OutputInvoiceFlow
Click "Page Layout" on the left sidebar, place the Output Invoice button, and click the "Save" button.
Run Flow
Click the "Output Invoice" button on the record page. The Bill Output Date is blank before running the flow.
A pop-up screen will appear. Click the "Next" button.
The Running screen will appear. Outputting the file and updating Bill Output Date.
The completion screen will appear. Click the "Done" button to close the flow screen.
The invoice file is output and today's date is set as the Bill Output Date.