Here is the Steps to File Upload Using Button With Guest User.
Step 1: Install these Packages:
Step 2: Create a Screen Flow
- Create Screen Element in the Screen Flow

- Create Record Element in the Screen Flow

- Create Apex Actions in the Screen Flow.

- Click Save.
- Click Activate.
Step 3: Create a Community Site or Experience Site.
Quick Find Box -> Sites -> Click New.

Step 4: Give the object access and field level access in the case object with read and create. Use the following Snapshot to give the field-level access.
Click the site -> Public Access Setting -> Search Case Object


Step 5: Click the Assigned User Button in the Profile.
Step 6: Click the Add Permission Set Button at the Bottom.
Step 7: Assign the File Upload Improved Permission set of this user.

Create an Aura Component
Step 8: Create Aura Component and Lightning Application. Use the below code:
Aura Component Bundle:
- embedFlowInExternalWebsite.cmp
<aura:component implements="flexipage:availableForAllPageTypes,lightning:availableForFlowActions" access="GLOBAL">
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:flow aura:id="flowData"/>
</aura:component>
- embedFlowInExternalWebsiteController.js
({
init : function (component) {
var flow = component.find("flowData");
flow.startFlow("YOUR_FLOW_API_NAME");
}
})
** replace the ‘YOUR_FLOW_API_NAME’ string with the name of the flow you want to run.
Create a Lightning Application
Lightning Application:
- embedFlowInExternalWebsiteApp.app
<aura:application access="GLOBAL" extends="ltng:outApp" implements="ltng:allowGuestAccess">
<aura:dependency resource="c:embedFlowInExternalWebsite"/>
</aura:application>
Step 9: Add your website’s domain to the CORS Allowed Origins List.
Quick Find Box -> CORS -> click New Button.

Step 10: Run this code:
<!DOCTYPE html>
<html>
<body>
<script src="https://curious-bear-q4ztlr-dev-ed.trailblaze.my.salesforce-sites.com/lightning/lightning.out.js"></script>
<div id="lightningLocator"></div>
<script>
$Lightning.use("c:embedFlowInExternalWebsiteApp",
function() {
$Lightning.createComponent(
"c:embedFlowInExternalWebsite",
{ },
"lightningLocator",
function(cmp) {}
);
},
'https://curious-bear-q4ztlr-dev-ed.trailblaze.my.salesforce-sites.com'
);
</script>
</body>
</html>
** Importantly here, you need to insert the URL to your Salesforce org in 2 places just before the /lightning/lightning.out.js.
One Response
Thank you Aman for the blog and spreading the knowledge.