• Vaibhav Desale
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Hi Everyone I am trying to intigrate docusign with salesforce. I am having one problem in my class when I am sending attachments of record. Code works fine when the record page is render as pdf.

I want to send attachments attached to  a record.

Apex class:
public with sharing class SendToDocuSignController {
    private final Opportunity opportunity;
   public String envelopeId {get;set;}
    private String accountId = '73ed93ba-5334-4983-9ba8-1515169d273a';
    private String userId = 'da3249f7-7f1c-4279-a3d6-989f016889b2';
    private String password = 'vaibhav939';
    private String integratorsKey = 'cf12560e-1211-4d73-a374-d8e649d8ae9d';
    private String webServiceUrl 
        = 'https://demo.docusign.net/api/3.0/dsapi.asmx?op=CreateAndSendEnvelope';
    
    public SendToDocuSignController(ApexPages.StandardController controller)
    {
        this.opportunity= [SELECT Id FROM Opportunity where id = :controller.getRecord().Id  ];
        envelopeId = 'Not sent yet';
        
        SendNow();
    }

   public void SendNow()
    {
        DocuSignAPI.APIServiceSoap dsApiSend 
            = new DocuSignAPI.APIServiceSoap();
        dsApiSend.endpoint_x = webServiceUrl;

        //Set Authentication
        String auth = '<DocuSignCredentials><Username>'+ userId 
            +'</Username><Password>' + password 
            + '</Password><IntegratorKey>' + integratorsKey 
            + '</IntegratorKey></DocuSignCredentials>';
        System.debug('Setting authentication to: ' + auth);
            
        dsApiSend.inputHttpHeaders_x = new Map<String, String>();
        dsApiSend.inputHttpHeaders_x.put('X-DocuSign-Authentication', 
            auth);
 
        DocuSignAPI.Envelope envelope = new DocuSignAPI.Envelope();
        envelope.Subject = 'Please Sign this Contract: ' 
            + contract.ContractNumber;
        envelope.EmailBlurb = 'This is my new eSignature service,'+ 
            ' it allows me to get your signoff without having to fax, ' +
            'scan, retype, refile and wait forever';
        envelope.AccountId  = accountId; 
         // Render the contract
        System.debug('Rendering the contract');
        //PageReference pageRef = new PageReference('/apex/RenderContract');
       // pageRef.getParameters().put('id',opportunity.Id);
       // Blob pdfBlob = pageRef.getContent();     
       
       Attachment att = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE Parentid = :opportunity.Id LIMIT 1];
       Blob pdfBlob = att.Body; 
 // Document
        DocuSignAPI.Document document = new DocuSignAPI.Document();
        document.ID = 1;
        document.pdfBytes = EncodingUtil.base64Encode(pdfBlob);
        document.Name = 'Contract';
        document.FileExtension = 'docx';
        envelope.Documents = new DocuSignAPI.ArrayOfDocument();
        envelope.Documents.Document = new DocuSignAPI.Document[1];
        envelope.Documents.Document[0] = document;
        
        // Recipient
        System.debug('getting the contact');
        //Contact contact = [SELECT email, FirstName, LastName 
         //   from Contact where id = :contract.CustomerSignedId];
        DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
        recipient.ID = 1;
        recipient.Type_x = 'Signer';
        recipient.RoutingOrder = 1;
        recipient.Email = 'vaibhav123desale@gmail.com';
        recipient.UserName = contact.FirstName + ' ' + contact.LastName;
        // This setting seems required or you see the error:
        // "The string '' is not a valid Boolean value. 
        // at System.Xml.XmlConvert.ToBoolean(String s)" 
        recipient.RequireIDLookup = false;      
         envelope.Recipients.Recipient = new DocuSignAPI.Recipient[1];
        envelope.Recipients.Recipient[0] = recipient;
       // Tab
        DocuSignAPI.Tab tab1 = new DocuSignAPI.Tab();
        tab1.Type_x = 'SignHere';
        tab1.RecipientID = 1;
        tab1.DocumentID = 1;
        tab1.AnchorTabItem = new DocuSignAPI.AnchorTab();
        tab1.AnchorTabItem.AnchorTabString = 'By:';
DocuSignAPI.Tab tab2 = new DocuSignAPI.Tab();
        tab2.Type_x = 'DateSigned';
        tab2.RecipientID = 1;
        tab2.DocumentID = 1;
        tab2.AnchorTabItem = new DocuSignAPI.AnchorTab();
        tab2.AnchorTabItem.AnchorTabString = 'Date Signed:';
          envelope.Tabs = new DocuSignAPI.ArrayOfTab();
        envelope.Tabs.Tab = new DocuSignAPI.Tab[2];
        envelope.Tabs.Tab[0] = tab1;        
        envelope.Tabs.Tab[1] = tab2;        
       System.debug('Calling the API');
        try {
            DocuSignAPI.EnvelopeStatus es 
            = dsApiSend.CreateAndSendEnvelope(envelope);
            envelopeId = es.EnvelopeID;
        } catch ( CalloutException e) {
            System.debug('Exception - ' + e );
            envelopeId = 'Exception - ' + e;
        }
      
    }
}

 Error :-
The DocuSign EnvelopeId:Exception - System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: The specified Anchor Tab string was not found in the document. Anchor Tab String "By:" not found.Anchor Tab String "Date Signed:" not found. faultcode=soap:Client faultactor=https://demo.docusign.net/api/3.0/dsapi.asmx?op=CreateAndSendEnvelope

I have refered this link:-
http://developer.force.com/cookbook/recipe/accessing-docusign-api-from-salesforcecom-to-send-contracts-for-esignatures

Please help me out to solve the issue. 
Thanks in advance.
I am  trying to create a new custom button on lead object which will assign assignment rule to lead.But something going wrong.i am new to coding as well as to salesforce.Please help:
code as below:

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} 

var leadStatus ="{!Lead.Status}";
var act = sforce.connection.query ("select id, whoid from task where who.type = 'LEAD' ");

var records = act.getArray("records");

if (leadStatus == 'Open - Not Contacted' && records.length !== 0)
{

var leadObj = new sforce.SObject("Lead");
leadObj.id = "{!Lead.Id}";
leadObj.Status = 'Open - Not Contacted';
leadObj.Country='India';
var result = sforce.connection.update([leadObj]);



var assignObj = sforce.connection.query("select id, name from assignmentrule where name = 'First' ");
var ruleid = assignObj.getArray("records")[0].get("id");
sforce.connection.assignmentRuleHeader = {}
sforce.connection.assignmentRuleHeader.assignmentRuleId=ruleid ;
var result = sforce.connection.update([leadObj]);




if (result[0].success =='false') {
alert(result[0].errors.message);
} else {
window.location.href = '/apex/your_page_goes_here?id="{!Lead.Id}"';
}


}

else
{
    alert('Check Lead Status and Schedule a meeting to continue');
}
I am new to salesforce... please help... I have requirement like: one custom object Employee having three field Name,Account,Contact. Now I am creating a vf page with this three fields... but when I am saving my record from vf only employyee name is reflected. it is showing account and contact blank. And also i want to go redirect at record page which i am creating through vf when saved.
vf and controller as follows
vf 
<apex:page StandardController="EmployeeA__c" extensions="classes" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlock title="Employee Page">
                <apex:PageBlockSection >
                    <apex:inputText value="{!Name}"/>
                    <apex:inputField value="{!EmployeeA__c.Account__c}"/>
                    <apex:inputField value="{!EmployeeA__c.Contact__c}"/>
                </apex:PageBlockSection> 
                <apex:pageBlockSection >
                    <apex:commandButton value="Save" action="{!Save}"/>
                    <apex:commandButton value="Cancel" action="{!Cancel}"/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>

controller

public with sharing class classes {

    public String Name { get; set; }

    public  String Account {get; set;}
    
    public String Contact {get; set;}
    
   

     
      VAD03__EmployeeA__c objdlt;
     private ApexPages.StandardController controller;
    public classes(ApexPages.StandardController controller) {
    this.controller = controller;
    

    }

public PageReference save() {
        /*
        VAD03__EmployeeA__c objdlt = new VAD03__EmployeeA__c();
        objdlt.Name=Name;
        objdlt.VAD03__Account__c=Account;
        objdlt.VAD03__Contact__c=Contact;
        insert objdlt;
        */
        controller.cancel();   
        PageReference congratsPage = Page.Congratulations;
        congratsPage.setredirect(true);
        return congratsPage;
    }
    
        public PageReference Cancel() {
            
            controller.cancel(); // This takes care of the details for you.
            PageReference congratsPage = Page.Congratulations;
            congratsPage.setRedirect(true);
            return congratsPage;
}
}
 
I am  trying to create a new custom button on lead object which will assign assignment rule to lead.But something going wrong.i am new to coding as well as to salesforce.Please help:
code as below:

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} 

var leadStatus ="{!Lead.Status}";
var act = sforce.connection.query ("select id, whoid from task where who.type = 'LEAD' ");

var records = act.getArray("records");

if (leadStatus == 'Open - Not Contacted' && records.length !== 0)
{

var leadObj = new sforce.SObject("Lead");
leadObj.id = "{!Lead.Id}";
leadObj.Status = 'Open - Not Contacted';
leadObj.Country='India';
var result = sforce.connection.update([leadObj]);



var assignObj = sforce.connection.query("select id, name from assignmentrule where name = 'First' ");
var ruleid = assignObj.getArray("records")[0].get("id");
sforce.connection.assignmentRuleHeader = {}
sforce.connection.assignmentRuleHeader.assignmentRuleId=ruleid ;
var result = sforce.connection.update([leadObj]);




if (result[0].success =='false') {
alert(result[0].errors.message);
} else {
window.location.href = '/apex/your_page_goes_here?id="{!Lead.Id}"';
}


}

else
{
    alert('Check Lead Status and Schedule a meeting to continue');
}
I am new to salesforce... please help... I have requirement like: one custom object Employee having three field Name,Account,Contact. Now I am creating a vf page with this three fields... but when I am saving my record from vf only employyee name is reflected. it is showing account and contact blank. And also i want to go redirect at record page which i am creating through vf when saved.
vf and controller as follows
vf 
<apex:page StandardController="EmployeeA__c" extensions="classes" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlock title="Employee Page">
                <apex:PageBlockSection >
                    <apex:inputText value="{!Name}"/>
                    <apex:inputField value="{!EmployeeA__c.Account__c}"/>
                    <apex:inputField value="{!EmployeeA__c.Contact__c}"/>
                </apex:PageBlockSection> 
                <apex:pageBlockSection >
                    <apex:commandButton value="Save" action="{!Save}"/>
                    <apex:commandButton value="Cancel" action="{!Cancel}"/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>

controller

public with sharing class classes {

    public String Name { get; set; }

    public  String Account {get; set;}
    
    public String Contact {get; set;}
    
   

     
      VAD03__EmployeeA__c objdlt;
     private ApexPages.StandardController controller;
    public classes(ApexPages.StandardController controller) {
    this.controller = controller;
    

    }

public PageReference save() {
        /*
        VAD03__EmployeeA__c objdlt = new VAD03__EmployeeA__c();
        objdlt.Name=Name;
        objdlt.VAD03__Account__c=Account;
        objdlt.VAD03__Contact__c=Contact;
        insert objdlt;
        */
        controller.cancel();   
        PageReference congratsPage = Page.Congratulations;
        congratsPage.setredirect(true);
        return congratsPage;
    }
    
        public PageReference Cancel() {
            
            controller.cancel(); // This takes care of the details for you.
            PageReference congratsPage = Page.Congratulations;
            congratsPage.setRedirect(true);
            return congratsPage;
}
}