Skip to main content
SFDC Developers
Flow

Validate Partner Proof-of-Completion with Flow and AI

Vinay Vernekar · · 4 min read

Automating Partner Proof-of-Completion Validation

A common challenge in partner management is validating proof-of-completion documents, often PDFs, before processing rebate claims. Partners may submit files lacking essential information like date, amount, quantity, or product. Relying on internal teams for this validation post-submission is inefficient and costly.

Limitations of a Custom LWC Approach

While a custom Lightning Web Component (LWC) can handle file uploads and integrate with Apex for external parsing, it places significant ownership burden on the development team. This includes managing the UI, file handling, error management, and Experience Cloud permissions, which can be overkill for this specific use case.

Leveraging Screen Flow for File Uploads

Salesforce's built-in File Upload screen component within a Screen Flow simplifies the initial step. When a partner uploads a file, Salesforce creates a Salesforce File. The ContentDocumentId can be captured and stored in a Flow variable, serving as the primary identifier for subsequent processing.

Initial Screen Component:

  • File Upload: Accepts PDF, PNG, JPG formats.
  • Output: Stores ContentDocumentId in a Flow text collection variable.

Extracting Data with Prompt Builder

Prompt Builder, augmented with multimodal AI capabilities, can process the uploaded document directly. The prompt template can be designed to inspect PDFs and images for specific data points. The key is to create a concise, directive prompt that focuses on extraction rather than inference.

Example Prompt Template:

You are reviewing a partner proof-of-completion document.
Extract the following fields from the uploaded file:
- completionDate
- amount
- quantity
- product

Only return values that are clearly present in the document. Do not infer or guess.
If a required field is missing, include the field name in missingFields.
Return the response in this JSON format:

{
  "completionDate": "",
  "amount": "",
  "quantity": "",
  "product": "",
  "missingFields": []
}

Crucially, the instruction "Do not infer or guess" ensures that the AI only returns explicitly present data, avoiding incorrect entries.

Structuring AI Output for Flow

The AI's response should be structured to be consumable by Flow. Predictable JSON fields allow for direct mapping to Flow variables:

  • completionDate → Date variable
  • amount → Currency or Number variable
  • quantity → Number variable
  • product → Text variable (or a lookup helper value)
  • missingFields → Text collection or delimited text value

This approach shifts the AI's role to data extraction, while Flow retains control over the business process logic.

Implementing Validation with the Decision Element

After the Prompt Builder action completes, the Flow utilizes a Decision element to check the missingFields variable.

  • If missingFields is not blank: The user is returned to the upload screen with a message indicating the missing information (e.g., "Amount", "Quantity"). This provides immediate feedback for correction.
  • If missingFields is blank: The Flow proceeds to the next stage.

Creating the Rebate Claim Record

Once all required fields are successfully extracted and validated, the Flow proceeds to create the Rebate Claim record (e.g., Rebate_Claim__c) with fields like Completion_Date__c, Claim_Amount__c, Quantity__c, and Product__c. The previously captured ContentDocumentId is used to link the uploaded proof file to the claim record via ContentDocumentLink, ensuring the file is associated even if the claim record was created after the upload.

Architectural Benefits

This architecture optimizes tool usage:

  • Flow: Manages the guided user experience and process logic.
  • File Upload Component: Handles the initial file intake.
  • Salesforce Files: Provides robust document storage.
  • Prompt Builder: Extracts structured data from documents using multimodal AI.
  • Flow: Validates extracted data and controls claim creation.

This pattern eliminates the need for custom LWCs for standard validation tasks, offering improved maintainability and adaptability for future business requirements.

Practical Considerations

  • Single vs. Multiple Files: Enforce a single file upload if the business process requires it.
  • Prompt Strictness: Reinforce the "do not infer or guess" instruction for accurate extraction.
  • Data Normalization: Implement a subsequent step to normalize extracted product names if they differ from Salesforce data (e.g., "Model X-1000" vs. "X1000 Commercial Unit").
  • Raw AI Response Storage: Consider storing the raw AI output for troubleshooting.
  • Human Review Path: Always include a mechanism for routing edge cases to human reviewers.

Key Takeaways

  • Integrate AI into existing Salesforce processes without relinquishing core business logic to AI.
  • Utilize Prompt Builder's multimodal capabilities for document data extraction.
  • Leverage Screen Flow for user interaction, file handling, and process orchestration.
  • This pattern enhances efficiency by automating data validation prior to record creation.

Share this article

Get weekly Salesforce dev tutorials in your inbox

Comments

Loading comments...

Leave a Comment

Trending Now