DocumentationCenterpoint for SalesforceSmartforms Apex API

Smartforms Apex API

For advanced business users and organizations, Centerpoint for Salesforce makes the Smartforms Apex API available. It lets your own Apex code and Flows create Smartforms, read the answers of completed forms, fetch their files, and remove forms.

All calls are global methods of the class MFAPI_SmartForms, in the package namespace mfwe. Each call has two forms:

  • A static method, for example mfwe.MFAPI_SmartForms.createSmartForm(params).
  • An instance method with the suffix Dyn, for example createSmartFormDyn(params), called on the object that mfwe.MFAPI_SmartForms.getInstance() returns. Use it where your code must call the package dynamically.

Every call takes one parameter object of the type named in the table below.

CallParameter typeReturns
createSmartFormCreateSmartformParamsThe address of the new form, or text that starts with ERROR:
getSmartObjectValuesGetSmartObjectValuesParamsSmartObjectValues: the table values of a form and its external metadata
getDialogValuesCompleteGetDialogValuesCompleteParamsDialogValuesComplete: the answers of a form and its files
getDialogExternalMetaDataGetDialogValuesCompleteParamsA map with the external metadata of a form
getSmartformFileContentGetSmartformFileContentParamsThe content of one file as a Base64 string
getAllSmartformFilesGetAllSmartformFilesParamsDialogFiles: the file information of a form, or null if the form is not found
getSmartformsWebhookUrlnoneThe address that receives Smartform webhooks
deleteDialogValuesDeleteDialogValuesParamsThe HTTP status code of the delete
deleteDialogValuesBulkDeleteDialogValuesBulkParamsThe HTTP status code of the bulk delete

The read calls work on the Smartform webhook records in Salesforce. They return what Doc Gen has already reported, so a form must have sent its webhook before you can read it.

Create a Smartform

createSmartForm creates a Smartform for a record and returns its address.

Field of CreateSmartformParamsMeaning
recordIdThe Salesforce record the form belongs to
dialogDefinitionIdThe id of the Smartform, from SmartForms Studio
smartformNameThe name shown in the Smartforms In Process list
dataTemplateThe data template to use. Leave blank to use the one named on the Smartform.
userIdentificationThe Salesforce user the form is created for. Blank means the current user. Otherwise a full name, e-mail address or profile name.
additionalValuesExtra values for the form, as name and value pairs
externalMetaDataExtra name and value pairs that are added to the form’s external metadata
participatingPartiesNot used by this call at the moment

The call does not send an SMS or an e-mail, and the form has no participants. Use the returned address to give someone the form.

mfwe.MFAPI_SmartForms.CreateSmartformParams params =
    new mfwe.MFAPI_SmartForms.CreateSmartformParams();
 
params.recordId = '0010Y00000A1b2cQAB';
params.dialogDefinitionId = '66f1a2b3c4d5e6f708192a3b';
params.smartformName = 'Customer questionnaire';
params.additionalValues = new Map<String, Object>{ 'Campaign' => 'Spring' };
 
String result = mfwe.MFAPI_SmartForms.createSmartForm(params);
 
if (result.startsWith('ERROR')) {
    System.debug('Could not create the form: ' + result);
} else {
    System.debug('Form address: ' + result);
}

Read a completed form

dialogFormId is the id of the form, which you find in the Dialog_Form_Id__c field of the Smartform webhook record.

mfwe.MFAPI_SmartForms.GetDialogValuesCompleteParams params =
    new mfwe.MFAPI_SmartForms.GetDialogValuesCompleteParams();
params.dialogFormId = '69b2930a53527bdd323bff10';
 
mfwe.MFSMF_ApiTypes.DialogValuesComplete form =
    mfwe.MFAPI_SmartForms.getDialogValuesComplete(params);
 
for (mfwe.MFSMF_ApiTypes.Values answer : form.Values) {
    System.debug(answer.property + ' = ' + answer.value);
}

getSmartObjectValues returns the smart tables of the form, with each table’s rows decoded into maps. getDialogExternalMetaData returns the external metadata that the form carried, such as the record id, the object name, the data template and the org id.

Read files

mfwe.MFAPI_SmartForms.GetAllSmartformFilesParams listParams =
    new mfwe.MFAPI_SmartForms.GetAllSmartformFilesParams();
listParams.dialogFormId = '69b2930a53527bdd323bff10';
 
mfwe.MFSMF_ApiTypes.DialogFiles files = mfwe.MFAPI_SmartForms.getAllSmartformFiles(listParams);
 
mfwe.MFAPI_SmartForms.GetSmartformFileContentParams fileParams =
    new mfwe.MFAPI_SmartForms.GetSmartformFileContentParams();
fileParams.dialogFormId = listParams.dialogFormId;
fileParams.property = files.Files[0].Property;
fileParams.fileId = files.Files[0].Id;
 
String base64 = mfwe.MFAPI_SmartForms.getSmartformFileContent(fileParams);

getAllSmartformFiles takes either dialogFormId or recordId, where recordId is the id of the Smartform webhook record. getSmartformFileContent fetches the file from Doc Gen as a Base64 string.

Delete forms

mfwe.MFAPI_SmartForms.DeleteDialogValuesParams params =
    new mfwe.MFAPI_SmartForms.DeleteDialogValuesParams();
params.dialogValuesId = '69b2930a53527bdd323bff10';
 
Integer statusCode = mfwe.MFAPI_SmartForms.deleteDialogValues(params);
System.debug('HTTP status: ' + statusCode);

The call returns the HTTP status of the delete in Doc Gen, for example 200 on success or 404 if the form is not found. deleteDialogValuesBulk deletes several forms at once. Put their ids in the list dialogValuesIds.

Webhook endpoints

The package publishes four endpoints on the public site named webhook, see Install and connect. Each is reached at the site address followed by /services/apexrest/mfwe/ and the name below. The Smartforms Webhook URL tab shows the full address of the first one.

EndpointMethodPurpose
SmartFormsWebhookPOSTDoc Gen reports the events DialogValuesStepComplete, DialogValuesComplete and DialogSigned. Salesforce updates the Smartform webhook record and publishes a platform event. A request whose org id differs from your org is ignored.
SmartFormsDialogFilesGETReturns the file information of a form as JSON. Give dialogFormId, recordId, or both. The answer is 400 when neither is given and 404 when no form is found.
AuthenticateWebhookGETReceives the sign-in from the Log in button. You do not call it yourself.
WebEditorWebhookGETThe editor reports that a letter is finished. Salesforce saves the PDF as a File when that was asked for, and removes the editor session. You do not call it yourself.

Platform events

When a Smartform is complete or signed, Salesforce publishes the platform event Smartform Webhook Response. Flows and Apex triggers can react to it, for example to run a field mapping when a form is complete.

FieldMeaning
RecordId__cThe Salesforce record the form was sent from
SobjectName__cThe object name of that record
DataTemplate__cThe data template of the form
Dialog_Definition_Id__cThe id of the Smartform
Dialog_Form_Id__cThe id of the form that was sent
EventType__cThe status, for example DialogValuesComplete or DialogSigned

The package also uses a second event, Smartform Processing, for its own work.