Skip to content

Sample Code for Retrieving and Sharing Files with Agentforce

License

Notifications You must be signed in to change notification settings

pozil/af-file-retrieve-share

Repository files navigation

Sample Code for Retrieving and Sharing Files with Agentforce

This repo holds an example of how you can implement two custom Apex actions that let you retrieve an invoice PDF from a third party accounting system (or more generally, a file from any external system) and share it publicly.

Read this blog post [link TBD] to learn more.

Requirements

This code requires the following:

  1. That you have a remote host that serves the invoice PDF. In my case, I wrote a basic HTTP Node server that I deployed on Heroku.
  2. That you deploy this code to a Salesforce Org with Agentforce.

Limitations

There are two important limitations to this solution:

  1. This implementation cannot handle files that are larger than the Apex heap size limit.
  2. Storing documents on the Platform consumes data storage and you’ll need to schedule some regular cleanup so that you org does not run out of space over time.

Installation

  1. Configure an Accounting_Service External Credential that points to the server that holds the documents.
  2. Optionnaly edit force-app/main/default/classes/GenerateInvoice.cls to match your service endpoint that returns the invoice. The default is /orders/ORDER_Id/invoice where ORDER_ID is the order ID.
  3. Deploy the content of this repo to your org:
    sf project deploy start -d force-app

Sample Prompts

You can experiment the actions with these sample prompts.

A basic example:

Get me a shareable password-protected link for the invoice of order O-12345

A more advanced example:

Draft an email to John Doe with a shareable and password-protected link to his invoice for order O-12345. Thank him for trusting ACME Corp.

About

Sample Code for Retrieving and Sharing Files with Agentforce

Topics

Resources

License

Stars

Watchers

Forks