Here is the code that was finally put in place. Nahuel was close - but I had to actually insert the echosign_dev1__SIGN_Agreement__c record first. // Build page reference for contract PDF & attach to the contract record
pageReference pdfPage = Page.ContractPDF;
pdfPage.getParameters().put('ContractId',pContractId);
blob pdfBody;
if(Test.isRunningTest()) {
pdfBody = blob.valueOf('Unit.Test');
} else {
pdfBody = pdfPage.getContentAsPDF();
}
// Build Echosign agreement record
echosign_dev1__SIGN_Agreement__c agreementRec = new echosign_dev1__SIGN_Agreement__c();
agreementRec.Name = 'Agreement - ' + contract.Account.Name + ' - ' + contract.startDate.format() ;
agreementRec.echosign_dev1__Signaturetype__c = 'e-Signature';
agreementRec.echosign_dev1__Recipient__c = contract.CustomerSignedId;
agreementRec.echosign_dev1__Recipient_User__c = administratorId;
agreementRec.echosign_dev1__Recipient_Signing_Order__c = 'Sequential';
agreementRec.echosign_dev1__Contract__c = pContractId;
agreementRec.echosign_dev1__Account__c = contract.AccountId;
agreementRec.echosign_dev1__Enable_Hosted_Signing__c = true;
insert agreementRec;
// insert the pdf as an attachment and set to the agreement
attachment pdfFile = new attachment();
pdfFile.isPrivate = false;
pdfFile.body = pdfBody;
pdfFile.parentId = agreementRec.id;
pdfFile.Name = 'Agreement ' + contract.Account.Name + ' - ' + contract.startDate.format() + '.pdf';
insert pdfFile;
답변 15개