Send with Template
Creates and sends a new SignatureRequest based off of the Template specified with the template_id parameter.
Universal Files Templates
HelloSign.SignatureRequestService.sendWithTemplate()
can only be used with Templates that use the "Upload File Method".To use a Universal Files Template (the "File Attached to Record Method"), either use
HelloSign.SendWithTemplate.SendWithTemplate()
or useHelloSign.SignatureRequestService.send()
, building the entire signature request in Apex.
Class: HelloSign.SignatureRequestService
Return type: SignatureRequestResponse
Methods
Name | Note |
---|---|
sendWithTemplate() | HelloSign__HelloSign_Signature_Request__c record is created immediately. |
sendWithTemplate(Boolean createSigReqRecordImmediately) | HelloSign__HelloSign_Signature_Request__c record is created later after the apex transaction if createSigReqRecordImmediately is set to false. |
Acceptable Parameters
Name | Type | Required | Note |
---|---|---|---|
originObjectId | Id | Set this if you want your HelloSign__HelloSign_Signature_Request__c record to populate the HelloSign__Related_Object_Id__c field. We will also attempt to populate the lookup field, HelloSign__Account__c for example if the Id is a Supported Object | |
test_mode | Boolean | The signature request will not be legally binding when set to true. | |
allow_decline | Boolean | Allows signers to decline to sign a document. | |
template_id | String | ✓ | HelloSign__TemplateUUID__c field value from the HelloSign Template (ie. the HelloSign__Template__c object) record.If the HelloSign__TemplateUUID__c field on your template record is empty, make sure the template's status is "Active" and that it's not a Universal Files template. See "Universal Files Template" note above. |
title | String | The title you want to assign to the SignatureRequest. | |
subject | String | The subject in the email that will be sent to the signers. | |
message | String | The custom message in the email that will be sent to the signers. | |
signing_redirect_url | String | The URL you want the signer redirected to after they successfully sign. | |
signers | Map<String, HelloSign.ServiceObjects.Signer> | ✓ | The list of recipients who will be required to sign. |
ccs | Map<String, HelloSign.ServiceObjects.CC> | List of recipients who will receive a copy only. | |
custom_fields | List<HelloSign.ServiceObjects.CustomField> | Editable custom_fields are only supported for single signer requests or the first signer of ordered signature requests. If more than one signer is assigned to the unordered signature request, any editor value is ignored and the field will not be editable. | |
fileIds | List<Id> | Accepted Id types are ContentDocument, Attachment, or Document. Setting this will append additional files to the signature request. Cannot use file_url when this is set. | |
file_url | List<String> | Setting this will append additional files to the signature request. Cannot use fileIds when this is set | |
signing_options | HelloSign.ServiceObjects.SigningOptions | If signing_options are not defined in the request, the allowed types will default to those specified in the account settings. | |
isLastCallout | Boolean |
HelloSign.SignatureRequestService sigReq = new HelloSign.SignatureRequestService();
/**
* Required Params
*/
Id sfdcTemplateId = 'a093F000005ariZQAQ';
HelloSign__Template__c sfdcTemplate = [
SELECT Name, HelloSign__Title__c, HelloSign__Message2__c, HelloSign__TemplateUUID__c
FROM HelloSign__Template__c
WHERE Id = :sfdcTemplateId];
// Use the HelloSign__TemplateUUID__c to set our template_id
sigReq.template_id = sfdcTemplate.HelloSign__TemplateUUID__c;
List<HelloSign__SignerRole__c> signerList = [
SELECT HelloSign__Role_Name__c,
HelloSign__SpecificContact__r.Name, HelloSign__SpecificContact__r.Email,
HelloSign__SpecificUser__r.Name, HelloSign__SpecificUser__r.Email,
HelloSign__SpecificEmail__c, HelloSign__SpecificFirstName__c
FROM HelloSign__SignerRole__c
WHERE
HelloSign__Template__c = :sfdcTemplateId
and HelloSign__IsCcRole__c = false];
sigReq.signers = new Map<String, HelloSign.ServiceObjects.Signer>();
for (HelloSign__SignerRole__c rec : signerList) {
HelloSign.ServiceObjects.Signer signerObj;
// Note: If no value is populated in the lookup, HelloSign__SpecificContact__c, for example
// then you need to provide your own value
if (rec.HelloSign__Role_Name__c.startsWith('Contact')) {
signerObj = new HelloSign.ServiceObjects.Signer(
rec.HelloSign__SpecificContact__r.Email,
rec.HelloSign__SpecificContact__r.Name);
} else if (rec.HelloSign__Role_Name__c.startsWith('User')) {
signerObj = new HelloSign.ServiceObjects.Signer(
rec.HelloSign__SpecificUser__r.Email,
rec.HelloSign__SpecificUser__r.Name);
} else {
signerObj = new HelloSign.ServiceObjects.Signer(
rec.HelloSign__SpecificEmail__c,
rec.HelloSign__SpecificFirstName__c);
}
// Adding signers for our request is role based, which is why we put the Role Name as our key
sigReq.signers.put(rec.HelloSign__Role_Name__c, signerObj);
}
/**
* Optional Params
*/
sigReq.test_mode = true;
sigReq.originObjectId = '001f200001cFD4x';
sigReq.allow_decline = true;
sigReq.title = sfdcTemplate.Name;
sigReq.subject = sfdcTemplate.HelloSign__Title__c;
sigReq.message = sfdcTemplate.HelloSign__Message2__c;
sigReq.signing_redirect_url = 'https://hellosign.com';
sigReq.ccs = new Map<String, HelloSign.ServiceObjects.CC>();
// SOQL would be the same as line 16 except we would check if HelloSign__IsCcRole__c = true
List<HelloSign__SignerRole__c> ccList;
for (HelloSign__SignerRole__c rec : ccList) {
String ccEmail;
// Note: If no value is populated in the lookup, HelloSign__SpecificContact__c, for example
// then you need to provide your own value
if (rec.HelloSign__Role_Name__c.startsWith('Contact')) {
ccEmail = rec.HelloSign__SpecificContact__r.Email;
} else if (rec.HelloSign__Role_Name__c.startsWith('User')) {
ccEmail = rec.HelloSign__SpecificUser__r.Email;
} else {
ccEmail = rec.HelloSign__SpecificEmail__c;
}
sigReq.ccs.put(rec.HelloSign__Role_Name__c, new HelloSign.ServiceObjects.CC(ccEmail));
}
// Append additional file to the signature request
ContentVersion cvRec = [SELECT ContentDocumentId FROM ContentVersion WHERE Title = 'myFile.pdf' LIMIT 1];
sigReq.fileIds = new List<Id>{ cvRec.ContentDocumentId };
// Can use this to send
HelloSign.ServiceObjects.SignatureRequestResponse response = sigReq.sendWithTemplate();
// Or this
// Do not create HelloSign_Signature_Request__c record immediately.
// This record is created later in case you want to call sendWithTemplate() for a list of records
HelloSign.ServiceObjects.SignatureRequestResponse response = sigReq.sendWithTemplate(false);
// object type: HelloSign.ServiceObjects.SignatureRequest
System.debug(response.signature_request);
// object type: HelloSign_Signature_Request__c
System.debug(response.signatureRequestRecord);
// object type: List<HelloSign.ServiceObjects.Warning>
System.debug(response.warnings);
Updated about 4 years ago