Skip to main content

Hello,

 

we implemented a custom method to use a existing envelope template and change the order of the documents;
added custom Merge fields and positioned them on the Document.

The fields are displayed correctly on the document - signing also works and we get the response of the envelope that the document has been signed.

But the data has not been written back to Salesforce.

 

public class docusign_DocuSignEnvelopeService {

@future(callout=true)
public static void processDocument(Id recordId){
try{
List<dfsle.Envelope> envelopes = new List<dfsle.Envelope>();

SBQQ__Quote__c quote = =SELECT Id, Name, SBQQ__PrimaryContact__r.Name, SBQQ__PrimaryContact__r.Email, cpqde_BankAccountOwner__c, cpqde_BankName__c, cpqde_SEPA_Consent__c
FROM SBQQ__Quote__c WHERE Id =: recordId]d0];

dfsle.Envelope envelope = createEnvelope(quote);

List<dfsle.Document> documents = attachDocuments(quote.Id);
envelope.withDocuments( documents );

List<dfsle.Tab> myTabs = mergeFields();

dfsle.Recipient recipient = addRecipient(quote);
recipient.withTabs(myTabs);
envelope.withRecipients(new List<dfsle.Recipient> {recipient});

setWriteBackOptions(envelope, quote.Id);

envelopes.add(envelope);

if(!envelopes.isEmpty()){
sendEnvelopes(envelopes);
}

} catch (dfsle.ValidationException e) {
// Handle validation exception
} catch (dfsle.APIException e) {
// Handle API exception
} catch(dfsle.DocuSignException e){

}
}

public static dfsle.Envelope createEnvelope(SBQQ__Quote__c quote) {

dfsle.Envelope env = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(quote.Id));

return env;
}


public static dfsle.Recipient addRecipient(SBQQ__Quote__c quote) {
dfsle.Recipient signer = dfsle.Recipient.fromSource(
quote.SBQQ__PrimaryContact__r.Name,
quote.SBQQ__PrimaryContact__r.Email,
null,
'Primary Contact',
new dfsle.Entity(quote.Id));

return signer;
}

public static List<dfsle.Document> attachDocuments(Id quoteId) {
List<dfsle.Document> documents = new List<dfsle.Document>();

documents.addAll(dfsle.DocumentService.getLinkedDocuments(
ContentVersion.getSObjectType(),
new Set<Id>{quoteId},
true
));

documents.add(dfsle.Document.fromTemplate(dfsle.UUID.parse(System.Label.docuSign_TemplateID), 'templatename'));

return documents;
}

public static void sendEnvelopes(List<dfsle.Envelope> envelopes) {
List<dfsle.Envelope> responseEnvelopes = dfsle.EnvelopeService.sendEnvelopes(envelopes);

dfsle.EnvelopeService.saveSentEnvelopes(responseEnvelopes);
}


public static void setWriteBackOptions(dfsle.Envelope env, Id quoteId){
env.withOptions(
new dfsle.Envelope.Options(
false,
new dfsle.Document.WriteBack(
quoteId,
dfsle.Document.WRITE_BACK_NAME_ENVELOPE_STATUS_PDF,
true,
true
),
new Map<String, Map<String, Object>> {
dfsle.Recipient.STATUS_SENT => new Map<String, Object> {
'SBQQ__Status__c' => 'PresentedToCustomer',
'cpqde_SignatureMethod__c' => 'E-Signature'
},
dfsle.Recipient.STATUS_COMPLETED => new Map<String, Object> {
'SBQQ__Status__c' => 'AcceptedByCustomer'
}
},
null
)
);
}

public static List<dfsle.Tab> mergeFields(){

dfsle.Tab bankAccountOwnerTab = new dfsle.TextTab()
.withMergeField(new dfsle.Tab.MergeField('SBQQ__Quote__c.cpqde_BankAccountOwner__c', null, null, true, false))
.withReadOnly(false)
.withPosition(new dfsle.Tab.Position(2, 1, 175, 220, 100, 20))
.withDataLabel('Quo Bank Account Owner');

dfsle.Tab bankNameTab = new dfsle.TextTab()
.withMergeField(new dfsle.Tab.MergeField('SBQQ__Quote__c.cpqde_BankName__c', null, null, true, false))
.withReadOnly(false)
.withPosition(new dfsle.Tab.Position(2, 1, 175, 240, 100, 20))
.withDataLabel('Quo Bank Name');

List<dfsle.ListTab.Item> items = new List<dfsle.ListTab.Item> {
new dfsle.ListTab.Item('I do consent',null,false),
new dfsle.ListTab.Item('I do not consent',null,false)
};

dfsle.Tab listTab = new dfsle.ListTab()
.withItems(items)
.withMergeField(new dfsle.Tab.MergeField('SBQQ__Quote__c.cpqde_SEPA_Consent__c', null, null, true, false))
.withRequired(true)
.withDataLabel('Sepa Consent')
.withPosition(new dfsle.Tab.Position(2, 1, 75, 480, null, null
));

return new List<dfsle.Tab>{bankAccountOwnerTab, bankNameTab, listTab};
}


}

 

If we use “just” the template without custom code it works (so it should should no be related to a permission issue)

I've reviewed your code and noticed that you passed the recipient status on the third parameter of the dfsle.Envelope.Options, which isn't the correct place. To writeback to the recipient object, you should define it at the fourth parameter of the dfsle.Envelope.Options. Please refer to the "Envelope.Options" > "Methods" section for more information: https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/envelope.html

Here is the code example of the writeback:

myEnvelope = myEnvelope.withOptions(
new dfsle.Envelope.Options(
false,
new dfsle.Document.WriteBack(
recordId,
dfsle.Document.WRITE_BACK_ENVELOPE_STATUS_PDF,
true,
true
),
new Map<String, Map<String, Object>>{
dfsle.Envelope.STATUS_COMPLETED => new Map<String, Object>{
'Opportunity.StageName' => 'Closed Won',
'Opportunity.Description' => 'envelope writeback',
}
},
new Map<String, Map<String, Object>>{
dfsle.Recipient.STATUS_COMPLETED => new Map<String, Object>{
'Description' => 'recipient writeback'
}
}
)
);

 


Hi ​@Byungjae.Chung ,

 

thanks for your response - but we still updated the code as you suggested but we still have issues with the Mergefields - the Fields a customer fills out in Docusign should be synched back to the refered Salesforce fields

 

    public static List<dfsle.Tab> mergeFields(){

dfsle.Tab bankAccountOwnerTab = new dfsle.TextTab()
.withMergeField(new dfsle.Tab.MergeField('SBQQ__Quote__c.cpqde_BankAccountOwner__c', null, null, true, false))
.withReadOnly(false)
.withPosition(new dfsle.Tab.Position(2, 1, 175, 220, 100, 20))
.withDataLabel('Quo Bank Account Owner');

dfsle.Tab bankNameTab = new dfsle.TextTab()
.withMergeField(new dfsle.Tab.MergeField('SBQQ__Quote__c.cpqde_BankName__c', null, null, true, false))
.withReadOnly(false)
.withPosition(new dfsle.Tab.Position(2, 1, 175, 240, 100, 20))
.withDataLabel('Quo Bank Name');

List<dfsle.ListTab.Item> items = new List<dfsle.ListTab.Item> {
new dfsle.ListTab.Item('I do consent',null,false),
new dfsle.ListTab.Item('I do not consent',null,false)
};

dfsle.Tab listTab = new dfsle.ListTab()
.withItems(items)
.withMergeField(new dfsle.Tab.MergeField('SBQQ__Quote__c.cpqde_SEPA_Consent__c', null, null, true, false))
.withRequired(true)
.withDataLabel('Sepa Consent')
.withPosition(new dfsle.Tab.Position(2, 1, 75, 480, null, null
));

return new List<dfsle.Tab>{bankAccountOwnerTab, bankNameTab, listTab};
}

did we miss anything?

 

Best regards

Kai

 

 


Reply