我最初有一个不带任何Web服务的Apex类,并尝试从“自定义按钮”调用它,然后遇到问题No operation available for request {http://soap.sforce.com/schemas/package/test_Controller}send, please check the WSDL for the service.'}
。现在,我将send()重写为Web服务,以便可以从“自定义按钮”进行调用。像
global class dhana_Test_Controller {
Private static string integration_key = 'xxx-xxx';
Private static string account_id = 'xxx-xxx';
Public string error_code { get; set; }
Private static string ds_server = 'https://www.docusign.net/api/3.0/dsapi.asmx';
Private static string trace_value = 'SFDC_004_SOAP_email_send';
Private static string trace_key = 'X-ray';
Public dhana_Test_Controller() { }
webservice static void send(String oppIds)
{
List<Opportunity> OppLst =[Select Name from Opportunity where id =: oppIds];
configure_sender();
do_send(OppLst);
}
Private static void configure_sender()
{
DocuSignTK.APIServiceSoap api_sender = new DocuSignTK.APIServiceSoap();
api_sender.endpoint_x = ds_server;
api_sender.inputHttpHeaders_x = new Map<String, String>();
String auth = '<DocuSignCredentials><Username>{!$Credential.Username}</Username>'
+ '<Password>{!$Credential.Password}</Password>'
+ '<IntegratorKey>' + integration_key + '</IntegratorKey></DocuSignCredentials>';
api_sender.inputHttpHeaders_x.put('X-DocuSign-Authentication', auth);
}
Private static void do_send(List<Opportunity> OppurLst)
{
string error_message,error_code,email_message,envelope_id;
DocuSignTK.APIServiceSoap api_sender = new DocuSignTK.APIServiceSoap();
// Check configuration
if (integration_key == 'xxx-xxxx-xxxx' ||
account_id == 'xxxx-xxxx-xxxx')
{
error_message = 'Please configure the Apex class DS_Recipe_Send_Env_Email_Controller with your integration key and account id.';
error_code = 'CONFIGURATION_PROBLEM';
return;
}
String file_contents = '<html><h1>Quote Document</h1>' + get_lorem(OppurLst)
+ '<p> </p>'
+ '<p>Signature: <span style="color:white;">signer1sig</span></p>'
+ '<p>Date: <span style="color:white;">signer1date</span></p></html>';
DocuSignTK.Document document = new DocuSignTK.Document();
document.ID = 1;
document.Name = 'Quote Document';
document.FileExtension = 'html';
document.pdfBytes = EncodingUtil.base64Encode(Blob.valueOf(file_contents));
DocuSignTK.Recipient recipient = new DocuSignTK.Recipient();
recipient.Email = 'abc@abc.com';
recipient.UserName = 'ABC';
recipient.ID = 1;
recipient.Type_x = 'Signer';
recipient.RoutingOrder = 1;
// The signer tab...
DocuSignTK.Tab signHereTab = new DocuSignTK.Tab();
signHereTab.Type_x = 'SignHere';
signHereTab.AnchorTabItem = new DocuSignTK.AnchorTab();
signHereTab.AnchorTabItem.AnchorTabString = 'signer1sig'; // Anchored for doc 1
signHereTab.AnchorTabItem.XOffset = 8;
signHereTab.RecipientID = 1;
signHereTab.Name = 'Please sign here';
signHereTab.ScaleValue = 1;
signHereTab.TabLabel = 'signer1sig';
// The dateSigned tab
DocuSignTK.Tab dateSignedTab = new DocuSignTK.Tab();
dateSignedTab.Type_x = 'DateSigned';
dateSignedTab.AnchorTabItem = new DocuSignTK.AnchorTab();
dateSignedTab.AnchorTabItem.AnchorTabString = 'signer1date'; // Anchored for doc 1
dateSignedTab.AnchorTabItem.YOffset = -6;
dateSignedTab.RecipientID = 1;
dateSignedTab.Name = 'Date Signed';
dateSignedTab.TabLabel = 'date_signed';
// Create an envelope and fill it in
DocuSignTK.Envelope envelope = new DocuSignTK.Envelope();
envelope.Subject = 'Please sign the Quote Document'; // Make the subject specific to the request
envelope.AccountId = account_id;
envelope.Tabs = new DocuSignTK.ArrayOfTab();
envelope.Tabs.Tab = new DocuSignTK.Tab[2];
envelope.Tabs.Tab.add(signHereTab);
envelope.Tabs.Tab.add(dateSignedTab);
envelope.Recipients = new DocuSignTK.ArrayOfRecipient();
envelope.Recipients.Recipient = new DocuSignTK.Recipient[1];
envelope.Recipients.Recipient.add(recipient);
envelope.Documents = new DocuSignTK.ArrayOfDocument();
envelope.Documents.Document = new DocuSignTK.Document[1];
envelope.Documents.Document.add(document);
if (String.isNotBlank(email_message))
{
envelope.EmailBlurb = email_message;
}
// Make the call
try
{
DocuSignTK.EnvelopeStatus result = api_sender.CreateAndSendEnvelope(envelope);
envelope_id = result.EnvelopeID;
System.debug('Returned successfully, envelope_id = ' + envelope_id);
}
catch (CalloutException e)
{
System.debug('Exception - ' + e);
error_code = 'Problem: ' + e;
error_message = error_code;
}
}
Private Boolean no_error()
{
return (String.isEmpty(error_code));
}
Private static String get_lorem(List<Opportunity> OLst)
{
String lorem = 'Hello World';
return lorem;
}
}
当我尝试通过
的“自定义”按钮调用send()时{!REQUIRESCRIPT("/soap/ajax/41.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/41.0/apex.js")}
sforce.apex.execute("dhana_Test_Controller","send",{oppIds:"{!Opportunity.Id}"});
在调试日志中,我看到类似的错误
System.CalloutException: IO Exception: External server did not return any content
我是apex类和自定义按钮的新手,非常感谢您的帮助。