I am for some reason having a problem with a URL being returned from Apex controller to Javascript when clicked a button. In Apex controller, the getSenderViewUrl method does not return null, it returns a real URL (https://appdemo.docusign.com/auth-from-console?code=...), but in the Javascript, it is always null, even though it is not returned null from the Apex Controller. Could anyone explain why is that? I added comments where you can see what is null and what is not. Thanks a lot.



    <lightning-button label="Send envelope with documents" title="Send envelope with documents" onclick={handleClick}>Test button</lightning-button>


Apex Javascript:

    import { LightningElement, api } from 'lwc';
import sendEnvelope from '@salesforce/apex/envelopeSendingController.sendEnvelope';
import getSenderViewUrl from '@salesforce/apex/envelopeSendingController.getSenderViewUrl';
export default class SendEnvelopeWithDocuments extends LightningElement {

    @api recordId;   
    handleClick() {


         mySourceId: this.recordId


    .then(getSenderViewUrl({ // calling the getSenderViewUrl method
        mySourceId: this.recordId
    .then((senderViewUrl) => {
        window.location.href = senderViewUrl; // senderViewUrl is null here 
    .catch((error) => {





Apex Controller:

public static void sendEnvelope(Id mySourceId) {
        Orders__c myOrder = [Select Id,DS_tempID__c, DS_envID__c, DS_signName__c,DS_signEmail__c From Orders__c where Id = :mySourceId]; 
        // Create an empty envelope with Opportunity Id as the source Id
        dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(mySourceId));

        //use the Recipient.fromSource method to create the Recipient
        dfsle.Recipient myRecipient = dfsle.Recipient.newEmbeddedSigner(
                    myOrder.DS_signName__c, // Recipient name
                    myOrder.DS_signEmail__c, // Recipient email
                    myOrder.Id); //This is the clientUserId in the API call

    myRecipient.withRole(new dfsle.Recipient.Role('Signer 1',1));
        //add Recipient to the Envelope
        myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient }); 
        //This pulls all the documents from the Opportunity Object and adds them to documents list
        List<dfsle.Document> documents = dfsle.DocumentService.getLinkedDocuments
                new Set<Id>{myOrder.Id},
        //add document to the Envelope
        myEnvelope = myEnvelope.withDocuments(documents); 
        // Send the envelope. 
        myEnvelope = dfsle.EnvelopeService.sendEnvelope(
            myEnvelope, // The envelope to send
            false); // Send now parameter not actually part of this method.
      System.debug('Sent ENvelope');
        myOrder.DS_envID__c = String.valueOf(myEnvelope.docuSignId);
        update myOrder;     

public static String getSenderViewUrl(Id mySourceId) {
   // String url = Apexpages.currentPage().getUrl();
    String url = 'http://www.google.com';
    System.debug('my source id: ' + mySourceId);
    Orders__c myOrder = [Select Id,DS_tempID__c, DS_envID__c, DS_signName__c,DS_signEmail__c From Orders__c where Id = :mySourceId];
    Url mySendingUrl = dfsle.EnvelopeService.getSenderViewUrl(
    new URL(url));

    System.debug('sending url: ' + mySendingUrl);
    System.debug('external form: ' + mySendingUrl.toExternalForm()); // this prints out a real URL
    return mySendingUrl.toExternalForm();
  • if you are calling the method like this: getSenderViewUrl({ // calling the getSenderViewUrl method... it'll likely break, because you are including a comment inside a JSON object, which is not allowed. Or was this for illustration purposes only? Commented Oct 16, 2022 at 19:07
  • Only for illustration.
    – DevelBase2
    Commented Oct 16, 2022 at 19:09

1 Answer 1


I've just figured it out.

Incorrect part:

.then(getSenderViewUrl({ // calling the getSenderViewUrl method
    mySourceId: this.recordId


.then(() => (getSenderViewUrl({
    mySourceId: this.recordId

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .