Question
Using Apex to send agreement for E Sign ,
Hi I am facing a challenge in sending Agreement for e sign with template ID. In template the AutoSend checkbox is checked. Below is the code. There is a custom object WorkOrder which will be created trough a queueable job when Opp reaches at a certain stage. The Class whic creating the workorder will then make an another queuebale exceute which will call the below code
public class QueueableWorkOrderAgreementTemplateSend extends QueueableBase{
Set<Id> workOrderIds;
public QueueableWorkOrderAgreementTemplateSend(Set<Id> workOrderIds) {
this.workOrderIds = workOrderIds;
}
public override void executeLogic(QueueableContext context) {
if(workOrderIds!=null && !workOrderIds.isEmpty()){
List<WorkOrder__c> woforSign = (WorkOrdersSelector.newInstance()).selectWorkOrders(workOrderIds);
Map<String,echosign_dev1.AgreementTemplateVariable> agreementTemplateVariables = new Map<String,echosign_dev1.AgreementTemplateVariable>();
for(WorkOrder__c wo : woforSign){
if(!String.isBlank(wo.TemplateId__c) && !String.isBlank(wo.WorkOrderSignee__c)){
echosign_dev1.AgreementTemplateService.load(wo.TemplateId__c,wo.Id,agreementTemplateVariables);
}
}
}
}
}
When the process is done I see only one Aggreement is send for Signature as for other work order the agrrements are in draft stage , and the error on the aggerement is no file attached to send. In apex log i also see this error
"You have uncommitted work pending. Please commit or rollback before calling out"
"You have uncommitted work pending. Please commit or rollback before calling out"
Our expectation is for each work order and agreement will be send for signature , each work order can have same template Id or can have different template id.
