如何解决Docusign Apextoolkit - 发送的信封未显示在 DocuSign 状态相关列表下
我能够从模板生成一个信封,并且它按照提供的机会对象 ID 的预期正确覆盖。然而,它不会更新与 Docusign 状态相关的列表,并且从文档中这应该会自动从 Docusign 发生。我在这个过程中遗漏了什么?
/**
* @description Accepts the Id of the associated primary object the envelope is being sent from.
* @param mySourceId
*/
public static void methodSendEnvelope(Id mySourceId) {
final string METHOD_NAME = 'SendEnvelope';
System.debug(CLASS_NAME + '.' + METHOD_NAME);
Boolean readyToProcess = false;
dfsle.Envelope myEnvelope = null;
//pickup the predefined object to template association
final Map<String,Docusign_YPO_Setting__mdt> settingsDocusignTemplate = new Map<String,Docusign_YPO_Setting__mdt> ();
For (Docusign_YPO_Setting__mdt settingItem :[Select Label,Template_Name__c,Template_ID__c,reminder__c,remindAfterDays__c,reminderFrequencyDays__c,expires__c,expiresAfterDays__c,expireWarnDays__c,email_Subject__c,email_Body__c
From Docusign_YPO_Setting__mdt]) {
settingsDocusignTemplate.put(settingItem.Label,settingItem);
}
//obtain the template for the envelope
String sourceName = idobjectName(mySourceId);
emailRecipent sender = new emailRecipent();
Map<String,object> templateInfo = new Map<String,object> ();
//if (settingsDocusignTemplate.get(sourceName) != null) {
//System.debug('Looking for Template: ' + settingsDocusignTemplate.get(sourceName).Template_Name__c);
//templateInfo = findTemplate(settingsDocusignTemplate.get(sourceName).Template_Name__c);
//}
switch on sourceName {
//when 'Lead' {
//lead whoTo = [Select Id,FirstName,LastName,X3rd_Party_Email__c,X3rd_Party_Name__c From Lead Where id = :mySourceId];
//System.debug(whoTo);
//sender.name = whoTo.X3rd_Party_Name__c;
//sender.eAddress = whoTo.X3rd_Party_Email__c;
//sender.role = 'Signer 1';
//readyToProcess = true;
//templateInfo.put('Source_Reference',(String) mySourceId + '~Lead');
//templateInfo.put('UUID',dfsle.UUID.tryparse('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'));
//templateInfo.put('name','Lead Third Party Validation');
//}
when 'Opportunity' {
Opportunity whoTo = [Select Id,Contact__c,Third_Party_Email__c,Third_Party_Name__c From Opportunity Where id = :mySourceId];
System.debug(whoTo);
sender.name = whoTo.Third_Party_Name__c;
sender.eAddress = whoTo.Third_Party_Email__c;
sender.role = 'Signer 1';
readyToProcess = true;
templateInfo.put('Source_Reference',(String) mySourceId); // + '~Opportunity'
templateInfo.put('UUID',dfsle.UUID.tryparse(settingsDocusignTemplate.get(sourceName).Template_ID__c));
templateInfo.put('name',settingsDocusignTemplate.get(sourceName).Template_Name__c);
}
when else {
throw new CustomException('UnkNow object type not accounted for. Please contact your System Administrator.');
}
}
System.debug('\tStart the envelope build');
System.debug(readyToProcess + '/' + (dfsle.UUID) templateInfo.get('UUID'));
if (readyToProcess && (dfsle.UUID) templateInfo.get('UUID') != null) {
myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(mySourceId));
//use the Recipient.fromSource method to create the Recipient
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(sender.name,// Recipient name
sender.eAddress,// Recipient email
null,//Optional phone number
sender.role,//Role Name. Specify the exact role name from template
null); //source object for the Recipient - new dfsle.Entity(mySourceId)
//add Recipient to the Envelope
myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });
//add email detail for the envelope
myEnvelope = myEnvelope.withEmail(settingsDocusignTemplate.get(sourceName).email_subject__c,settingsDocusignTemplate.get(sourceName).email_body__c);
//Could provide automatic notifications as well based off of criteria
final boolean dfsle_reminder = settingsDocusignTemplate.get(sourceName).reminder__c;
final integer dfsle_remindAfterDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).remindAfterDays__c); //wait before sending reminder
final integer dfsle_reminderFrequencyDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).reminderFrequencyDays__c); //days between reminders
final boolean dfsle_expires = settingsDocusignTemplate.get(sourceName).expires__c; //does the env expire
final integer dfsle_expiresAfterDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).expiresAfterDays__c); //number of days be env expires
final integer dfsle_expireWarnDays = Integer.valueOf(settingsDocusignTemplate.get(sourceName).expireWarnDays__c); //warning days before env expires
final boolean dfsle_updateChatter = false; //do we update chatter with updates; would have to relate the env to a contact
dfsle.Notifications reminderNotifications = new dfsle.Notifications(dfsle_reminder,dfsle_remindAfterDays,dfsle_reminderFrequencyDays,dfsle_expires,dfsle_expiresAfterDays,dfsle_expireWarnDays,dfsle_updateChatter);
//Assign the reminder notifications to the envelope
myEnvelope = myEnvelope.withnotifications(reminderNotifications);
//create a new document for the Envelope
dfsle.Document myDocument = dfsle.Document.fromTemplate((dfsle.UUID) templateInfo.get('UUID'),// templateId in dfsle.UUID format
(String) templateInfo.get('name')); // name of the template
//add document to the Envelope
myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });
//populate the custom fields on the Envelope
List<dfsle.CustomField> myCustomFields = new List<dfsle.CustomField>();
myCustomFields.add(new dfsle.CustomField('text','DSFSSourceObjectId',(String) templateInfo.get('Source_Reference'),null,false,true));
--> myCustomFields.add(new dfsle.CustomField('text','##SFOpportunity',true));
myEnvelope = myEnvelope.withCustomFields(myCustomFields);
if (methodShipEnvelope(myEnvelope)) {
switch on sourceName {
//when 'Lead' {
////nothing to update yet
//}
when 'Opportunity' {
Opportunity updateOpp = new Opportunity();
updateOpp.id = mySourceId;
updateopp.Certification_Status__c = 'Requested';
updateopp.Third_Party_Sent_Date__c = Date.today();
updateopp.Send_3rd_Party_Verification_Docusign__c = false;
update updateOpp;
}
//Add any new sources here for follow up
}
}
} else {
if ((dfsle.UUID) templateInfo.get('UUID') == null) {
throw new CustomException('A valid Docusign Template was not found. Please contact YPO help desk services to resolve.');
} else {
throw new CustomException('The sourceId provided was not for a currently configured object. Please contact YPO help desk services to resolve.');
}
}
}
这是我需要更新的东西吗? Docusign 的文档似乎不支持这一点;假设这是由Docusigns 方处理的。
查看了 Docusign Status 对象,发现状态正在加载,但即使我通过 CustomFields 提供了该信息,但并未填充 Opportunity 参考字段。
在行为没有改变的情况下尝试了以下操作;
templateInfo.put('Source_Reference',(String) mySourceId + '~Opportunity');
templateInfo.put('Source_Reference',(String) mySourceId + '~Opportunity__c');
templateInfo.put('Source_Reference',(String) mySourceId);
模板与机会中的信息合并得很好,但对象引用 Id 未在 Docusign 状态对象 dsfs__Opportunity__c 字段上传播。
在与 Docusign 支持协商后更新:
new dfsle.CustomField ('text',(String) myOpportunity.Id,false);
这解决了问题!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。