• Developer Code
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hi All,

I am trying to send the document through the docusign once there is an attachment on the opportunity by using the docusign API. Thanks in Advance....!!!!
Error Message:

Exception - System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: An Error Occurred during anchor tag processing. Invalid document faultcode=soap:Client faultactor=https://demo.docusign.net/api/3.0/dsapi.asmx
public class AttachmentTriggerHandlerManager {


public void oppSendtoDocusign(map<Id,Attachment> newmap)
{
       set<ID> oppParentIDs = new set<ID>();
        for(Attachment oAttach: newmap.values()){
            if(Schema.Opportunity.getSObjectType() == oattach.parentID.getsobjectType()){
               oppParentIDs.add(oAttach.ID); 
            }
        }
         sendDocNow(oppParentIDs);
}
@Future(callout=true)
public static void sendDocNow(set<ID> attachmentIDS)
{
     map<ID,Opportunity> oattachMap = new map<ID,Opportunity>();
     set<ID> parentIDs = new set<ID>();
     
        for(Attachment oatt: [SELECT ID,ParentId FROM Attachment WHERE ID IN: attachmentIDS]){
                parentIDs.add(oatt.ParentID);
         }
         
        oattachMap = new map<ID,Opportunity>([SELECT Id,AccountID,Account.Name,Account.primary_email__c FROM Opportunity WHERE ID IN: parentIDS]);
                                                       
        for(Attachment  oattachment : [SELECT ID,ParentId,Name FROM Attachment WHERE ID IN: attachmentIDS]){
         Opportunity oppObj = oattachMap.get(oattachment.ParentId);    
         String envelopeId;
         String accountId = 'e7bee96b-5fcf-4d0d-8d67-c91349b4a2dd';
         String userId = 'ravinder4a2@gmail.com';
         String password = 'believe4a2';
         String integratorsKey = 'MOVE-d2cdaebb-3c48-4868-a026-c9409ce57faf'; 
         String webServiceUrl  = 'https://demo.docusign.net/api/3.0/dsapi.asmx';

        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 = 'Oder Confirmation'; 
            //+ 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',contract.Id);*/
        Blob pdfBlob = [SELECT Body FROM Attachment WHERE Id =: oattachment.ID].Body;    

        // Document
        DocuSignAPI.Document document = new DocuSignAPI.Document();
        document.ID = 1;
        document.pdfBytes = EncodingUtil.base64Encode(pdfBlob);
        document.Name = oattachment.Name;
        document.FileExtension = 'pdf';
        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];*/
//        Account  oAccount = [select Name,Primary_Email__c FROM Account WHERE ID=: oppObj.AccountID ];
        DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
        recipient.ID = 1;
        recipient.Type_x = 'Signer';
        recipient.RoutingOrder = 1;
        recipient.Email = oppObj.Account.Primary_Email__C;
        recipient.UserName = oppObj.Account.Name;

        // 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 = new DocuSignAPI.ArrayOfRecipient();
        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:';
        tab1.AnchorTabItem.AnchorTabString = 'Signed:';


        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:';
        tab2.AnchorTabItem.AnchorTabString = 'Date:';

        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;
        } 
        dsfs__DocuSign_Status__c doc = new dsfs__DocuSign_Status__c();
        doc.Notes__c = envelopeId;
        doc.dsfs__Opportunity__c = oppObj.ID;
        insert doc;
        system.debug('****envelopeId****'+envelopeId);
       
 }       
}
}


 
Hi All,

I wanted to impelemt the Asset hierarchy in the tree structure where we have tons of Assets in 5 levels.
We have approximately 2 million assets where we need to implement the tree view as parent -> child -> grand child  on VF page.

Can anyone suggest me the best approach to develop bcoz i think we have lot of limitations in Salesforce as viewstate, heap size if we implement by usinf vf page & Controller.

Please help me ASAP & thanks in Advance

Please  sugges