0

I have a Canvas App in a Lightning Component that I'd like to display in a Modal/Overlay when a User clicks on a button (within a different Lightning Component). The Canvas App component uses the force:hasRecordId to pass to a controller. How can I get the button click to launch in a new window while still passing the RecordId as needed?

I've got the below Component/Controller working fine with the Lightning UI, just need to be able to launch the Canvas in a Model/Overlay:

Component

<aura:component implements="flexipage:availableForAllPageTypes,force:apphostable,lightning:isUrlAddressable,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="AgencyLoanCanvasHandler">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="loanParams" type="String" access="global"/>
        <div>
            <force:canvasApp developerName="Agency_Loan_Canvas_App" parameters="{!v.loanParams}" width="100%"/>
        </div>
</aura:component>

JS Controller

({
    doInit : function(component, event, helper) {        
        var loanId = component.get("v.recordId");
        var action = component.get("c.getLoanParameters");  
        action.setParams({ 
            "strOppId" : loanId
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(component.isValid() && state === "SUCCESS"){
                var result = response.getReturnValue();
                var loanParam = result;
                component.set("v.loanParams",loanParam);
                console.log(loanParam);
            } 
            else if(state === "ERROR") {
                var errors = response.getError();
                console.log("An error ocurred");
            }
        })
        $A.enqueueAction(action);
    }
})

Apex Controller

public class AgencyLoanCanvasHandler {

    @auraEnabled
    public static String getLoanParameters(String strOppId) {

        Opportunity opp = [Select Id, Name, RecordType.Name, Loan_Number_formula__c, User_Email__c, Amount From Opportunity Where Id = :strOppId];

        String userId = userInfo.getUserId();
        String Amount = string.valueOf(opp.Amount);

        JSONGenerator gen = JSON.createGenerator(true);
        gen.writeStartObject();
        gen.writeStringField('loanNumber', opp.Loan_Number_formula__c);
        gen.writeStringField('loanId', opp.Id);
        gen.writeStringField('loanName', opp.Name);
        gen.writeStringField('userEmail', opp.User_Email__c);
        gen.writeStringField('userId', userId);
        gen.writeStringField('RecordType', opp.RecordType.Name);
        gen.writeStringField('Amount', Amount);
        gen.writeEndObject();
        System.debug('>>>'+gen.getAsString());

        return gen.getAsString();

    }

}

Trying to call the Canvas from a button on a separate component, need to be able to pass the RecordId

1
  • How the canvas app is created, is it embedding the different salesforce org page or some other system page. Surrounding code could also help here to understand and dig deeper. Dec 1 '19 at 5:07
0

Decided to use a standard Modal in a child component to display.

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.