0

My requirement is to have a component which I will be calling from a button which should redirect me to a docusign page.

I want to pass the docusign parameters int the vf url.

How can a docusign vf page be called from a lightning component.

What I am trying to do here is:

Component:::

<aura:component controller="OnBoardingDocusignHelper"
                implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction">

    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="oppRecord" type="Object" />
    <aura:attribute name="recordError" type="String" />

    <aura:attribute name="docusignpageUrl" type="String" />

    <aura:handler name="render" value="{!this}" action="{!c.onRender}"/>
    <aura:attribute name="renderVal" type="boolean" default='true'/>

   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <force:recordData aura:id="recordEditor"
                      layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetError="{!v.recordError}"
                      targetRecord="{!v.record}"
                      targetFields ="{!v.oppRecord}"
                      fields="Name, StageName, Probability, Sender_Notification__c, OwnerId, Owner.Name, Product_Specialist2__c"
                      mode="EDIT"/>

    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            {!v.recordError}</div>
    </aura:if>

</aura:component>

controller::::::

({
    doInit : function(component, event, helper) {

        let action = component.get("c.getDocusignUrl");
        action.setParams({
            "sourceId": component.get("v.recordId")
        });
        action.setCallback(this,function(response){
            //check state and do error handling
            component.set("v.docusignpageUrl",response.getReturnValue());
            console.log("docusignpageUrl => ",response.getReturnValue());

        });
        $A.enqueueAction(action);
    },

    onRender : function(component, event, helper) {
        var opportunity = component.get('v.oppRecord');
        if(opportunity != null) {
            console.log('opportunity:::::::::::::: ' + opportunity);
            var probability = component.get('v.oppRecord.Probability');
            console.log('probability:::::::::::::: ' + probability);
            var name = component.get('v.oppRecord.Name');
            var stageName = component.get('v.oppRecord.StageName');
            var owner = component.get('v.oppRecord.Owner.Name');
            var productOwner = component.get('v.oppRecord.Product_Specialist2__c');

            //setting the checkbox true
            component.set("v.oppRecord.Sender_Notification__c", true);

            var renderVal=component.get('v.renderVal')
            if(probability >= 50 && renderVal) {
                console.log('inside LC');

                component.find("recordEditor").saveRecord(function(saveResult) {
                    console.log('saveresult:::::::::::' + saveResult.state);
                    if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                        var resultsToast = $A.get("e.force:showToast");
                        resultsToast.setParams({
                            "title": "Saved",
                            "message": "The record was saved."
                        });
                        resultsToast.fire();

                        var urlEvent = $A.get("e.force:navigateToURL");
                        urlEvent.setParams({                        
                            "url" :  component.get('v.docusignpageUrl') 
                        });
                        urlEvent.fire();
                    }
                });
            } else if(probability < 50){ 

                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Error!",
                    "message": "Opportunity should be more than 50%.",
                    "type" : "error"
                });
                toastEvent.fire();
                $A.get("e.force:closeQuickAction").fire();
            } 
        }
    }
})

apex class::::::

public class OnBoardingDocusignHelper {

    @AuraEnabled(cacheable=true)
    public static string getDocusignUrl(String sourceId){
        Pagereference pg = Page.dsfs__DocuSign_CreateEnvelope;
        pg.getParameters().put('SourceID',sourceId);
        pg.getParameters().put('DST','**-**-**-**-**');
        pg.getParameters().put('LA','0');
        return pg.getUrl();
    }
}

Error: The link you followed isn’t valid. This page requires a CSRF confirmation token. Report this error to your Salesforce administrator I need the url be something like this. Appreciate the response.

2
  • It would be helpful if you can add what problem you are facing. Did you implement above approach? Did you get any error? If so, screenshot of error? And any other information that would be helpful – salesforce-sas Jul 22 '19 at 4:27
  • hi @salesforcesas I added the error – user905 Jul 22 '19 at 4:45
1

You are getting this error because that page has "Require CSRF protection on GET requests" enabled in its definition.

You should get the url from apex:

@AuraEnabled(cacheable=true)
public static string getDocusignUrl(String SourceID, String DST){
    Pagereference pg = Page.dsfs__DocuSign_CreateEnvelope;
    pg.getParameters().put('SourceID',SourceID);
    pg.getParameters().put('DST',DST);
    return pg.getUrl();
}

Then the url you get will look like this:

/apex/dsfs_docusign_createenvelope?DST=dst_value&SourceID=rec_id&_CONFIRMATIONTOKEN=VmpFPSxNakF4T1Mwd055MHlObFF3TXpvME16b3dNUzQxT0RSYSxmUUVfQ1o5YU9sUzFPaUc3bVdvYnRuLE16QmtNRGRq&common.udd.actions.ActionsUtilORIG_URI=%2Fapex%2Fdsfs_docusign_createenvelope

You should get the url in init of component and store. Then use it while navigating. In cmp:

<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="docusignpageUrl" type="String" />

Then in JS:

doInit : function(component, event, helper) {
    let action = component.get("c.getDocusignUrl");
    action.setParams({
                    SourceID: 'your_SourceID_value',
                    DST: 'your_DST_value'
                });
    action.setCallback(this,function(response){
        //check state and do error handling
        console.log("docusignpageUrl => ",response.getReturnValue());
        component.set("v.docusignpageUrl",response.getReturnValue());
    });
    $A.enqueueAction(action);
},
onRender : function(component, event, helper) {
    // your logic of saving data and inside callback
    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
        "url":component.get("v.docusignpageUrl")                        
        // "url" : "apex/dsfs__DocuSign_CreateEnvelope'+ ',null,' + '[SourceID = opportunity, LA = 0,   DST = \'----', '\CRL = \'LoadDefaultContacts~1\']"

    });
    urlEvent.fire();
}

Note: you should be using lightning:navigation library with page-reference of webpage type as a best practice. Also the url you get here will be readable.

9
  • hi, can you please explain this - Page.dsfs_DocuSign_CreateEnvelope, also I need to pass parameters in my url like DST='docusign id' and la=0, which is the issue – user905 Jul 23 '19 at 0:27
  • updated answer to pass parameters – salesforce-sas Jul 23 '19 at 3:43
  • this line gives error - I am not able to understand this. -Page.dsfs_DocuSign_CreateEnvelope – user905 Jul 23 '19 at 4:40
  • Also, wanted to mention I am trying to use LDS record editor, so if I am using this class for the url, I'd have to pass my record id here right, so how to pass that, I am just starting with my first component in lightning so – user905 Jul 23 '19 at 4:43
  • I created dsfs_DocuSign_CreateEnvelope page, but for you, it was dsfs namespace in managed package. You should have double underscore "__" after namespace. However I updated code above to pass parameters and also as per your page name – salesforce-sas Jul 23 '19 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.