Editor Apex API
For more advanced business users and organizations Centerpoint for Salesforce has made available the Editor Apex API giving the organization the ability to fully customize and integrate Centerpoint letters, documents and archive functionality into their business applications in Salesforce.
The Editor Apex API will give access to low level functionality that gives full control, such as:
- finding templates
- retrieving data
- creating letter editing sessions
- creating, sending and archiving documents on demand and in batch
- uploading documents
- reading and writing metadata in the document archive
- searching for and retrieving documents
- saving the generated PDF as a Salesforce File on the record
Save the PDF as a File
The calls that create an editor session, webEditDocument and webEditDocumentStandard, have the field attachPdfToRecord. When it is true, the PDF of the finished document is also saved as a Salesforce File on the record. This only happens when the Generated PDF setting is enabled, see Metaforce Generated PDF. With the storage mode AlwaysStore the PDF is saved whatever the field says.
The response of a call that creates and distributes a document, DistributeSendResponse, has two fields for this. ContentDocumentId is the id of the saved file. fileAttachError holds the reason when the document was created but the file could not be saved. It does not stop the document from being created.
Metadata with lists and nested values
Metadata can hold more than text. archiveUpload takes metadataObjects, and dynamoUpdateMetadata and archiveUpdateMetadata take updateColumnsObjects. Both are maps from a name to any value, so a metadata field can be a list, a nested object or a true or false value. Search results return the same kind of map in MetadataObjects. The plain metadata and updateColumns maps keep working and only hold text.
Examples
Each example shows the main call. The parameter types are listed in the reference below.
Create an editor session
mfwe.MFAPI_WebEditor.WebEditDocumentStandardParams params =
new mfwe.MFAPI_WebEditor.WebEditDocumentStandardParams();
params.metaFile = 'Salesforce';
params.documentName = 'WelcomeLetter';
params.fileName = 'Welcome letter';
params.sObjectName = 'Contact';
params.recordId = '0030Y00000B2c3dQAC';
params.dataService = 'DEFAULT';
params.attachPdfToRecord = true;
mfwe.MFWED_ApiTypes.WebEditDocumentResponse response =
mfwe.MFAPI_WebEditor.webEditDocumentStandard(params);
System.debug(response.StartURL);
System.debug(response.error);Open StartURL in a browser to edit the letter.
Create and archive a document
mfwe.MFAPI_WebEditor.CreateDocumentParams params =
new mfwe.MFAPI_WebEditor.CreateDocumentParams();
mfwe.MFWED_ApiTypes.ComplexNode dataNode = new mfwe.MFWED_ApiTypes.ComplexNode(
'Contact',
'0030Y00000B2c3dQAC',
'Letter',
'Welcome letter'
);
params.metaFile = 'Salesforce';
params.documentName = 'WelcomeLetter';
params.distributionMethod = 'Archiving';
params.nodes = dataNode;
mfwe.MFWED_ApiTypes.DistributeSendResponse result =
mfwe.MFAPI_WebEditor.createDocument(params);
System.debug(result.JobId + ' ' + result.DocId + ' ' + result.error);Search the archive
mfwe.MFAPI_WebEditor.ArchiveSearchParams params =
new mfwe.MFAPI_WebEditor.ArchiveSearchParams()
.addSearchSpec('SSN', '123456789012', 'EQ')
.setSortByKey('ArchiveDate')
.setSortOrder('DESC')
.setSkip(0)
.setTake(10);
mfwe.MFWED_ApiTypes.ArchiveSearchResponse found =
mfwe.MFAPI_WebEditor.archiveSearch(params);
System.debug(found.DocumentModel.size());Related
- Data templates describe the data a template receives.
- Batch sending uses
startPrintOrderBatchJob. - Smartforms Apex API and Workflow Apex API.
Apex Reference Guide
Miscellaneous
MFAPI_WebEditor
This class is the main entry point for the Editor Apex API.
MFWED_ApiTypes
This class contains the data types used by the Editor Apex API.
MFCORE_DataService
This class provides methods to retrieve data from Salesforce and transform it into a complex node.
MFCORE_DataServiceInterface
This class provides the interface for the methods to retrieve data from Salesforce and transform it into a complex node.
MFCORE_TestFactory
This class provides methods to create test data for Salesforce objects.
CustomPermissionsReader
This class is designed to help with caching the results of querying (via SOQL) Custom Permissions for the current user, it will load all defined Custom Permissions in one go for a given default or specified namespace (so not all defined in the org). This is done on the basis the caller will make 2 or more calls to the hasPermission method, thus benefiting from the bulkification approach used. Note that the query to the database is demand loaded only on the first call to the hasPermission method thus constructing the object carries no SOQL / database overhead.