Skip to content

Instantly share code, notes, and snippets.

@forcementor
Last active December 16, 2017 05:22
Show Gist options
  • Select an option

  • Save forcementor/81678cca6c1c67865307b4ba75cc9752 to your computer and use it in GitHub Desktop.

Select an option

Save forcementor/81678cca6c1c67865307b4ba75cc9752 to your computer and use it in GitHub Desktop.
//====================================================================
// Name: MicroserviceManagerDemo
// Type: Class
// Purpose: Demo routines for demoing the MicroserveManager
// Created by: Don Robins
// Created on: Dec 1, 2017
//====================================================================
// Setup Steps: (NOTE- Run this in Classic, NOT in Lightning Experience as Attachments are deprecated.)
// 1) Clone the PFDParser Repo and deploy to a Heroku instance from:
// https://github.com/forcementor/pdf-convert.git
// 2) Set up a DE org and add a Named Credential named PDFParser with no authentication and select all defaults.
// 3) Set the URL to your Heroku app URL
// 4) Add a long text field Parsed_Text__c of at least 10k to the Contact object
// 5) Add the field to the Page Layout in a new section for easy visibility
// 6) Add the MicroserviceManager apex class to your DE org, and then add this class after
// 7) Create a simple document and generate a PDF
// 8) Attach the PDF as an Attachment (NOT A file!) to a selected Contact
// 9) Grab the ID of the contact from the URL of the detail page and run the following code in Execute Anonymous:
/*
//Set up sample contact Tim Barr
Id defaultId = '<your contact id with the PDF attachment>';
//Invoke the async call for the microservice.
MicroserviceManagerDemo.runService(defaultId);
//Execute this query to see the data as it may not be visible in the log on the sync process.
//SELECT Name, Parsed_Text__c FROM Contact WHERE Id = '<your contact id with the PDF attachment>'
*/
//====================================================================
public class MicroserviceManagerDemo {
public static void runService(id parentId) {
Contact parentContact;
//First fetch the data from the Contact and display.
parentContact = MicroserviceManager.getContactById(parentId);
system.debug('Contact Parsed_Text__c starting state: ' + parentContact.Parsed_Text__c);
//Clear the order data and show.
parentContact.Parsed_Text__c = null;
update parentContact;
system.debug('Contact Parsed_Text__c cleared state: ' + parentContact.Parsed_Text__c);
//Invoke the service call.
MicroserviceManager.parsePDFToText(new List<id>{parentId});
//Retrieve the updated parent record with the parsed text and show (it may not be there yet.)
parentContact = MicroserviceManager.getContactById(parentId);
system.debug('Contact Parsed_Text__c set state: ' + parentContact.Parsed_Text__c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment