You need to sign in to do that
Don't have an account?
Robert Davis 16
Passing Value to Apex to Javascript Helper
I have a Lightning Component that has a button that I would like to click and have it open an external URL with values from the fields from the current Opportunity Record.
I can not figure out how to get the recordId from component to Apex Controller and then the fields back to the Javascript Helper to form the URL.
Javascript Component
I would appreciate any assistance. Thank you in advance.
Robert
I can not figure out how to get the recordId from component to Apex Controller and then the fields back to the Javascript Helper to form the URL.
Javascript Component
<aura:component implements="force:lightningQuickAction,force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global" controller="CAFController"> <aura:attribute name="recordId" type="Id" /> <div id="aura-page"> <div class="container"> <ui:button class="btn" label="CAF Form" press="{!c.navigate}"/> </div> </div> </aura:component>Javascript Controller
({ navigate : function(component, event, helper) { helper.navigate(component); } })Javascript Helper
({ navigate : function(component) { var action = component.get("c.getOpportunity"); action.setParams({opportunityId: component.get("v.recordId")}); var urlEvent=$A.get("e.force:navigateToURL"); var partOneURL = 'https://XXX21.springcm.com/atlas/Forms/UpdateFormDoc.aspx?aid=9124&FormUid=8beXXXXX-d9b0-e611-bb8d-6c3be5XXXXXXX'; urlEvent.setParams({"url": partOneURL}) urlEvent.fire(); } })Apex Controller
public class CAFController { @AuraEnabled public static Opportunity getOpportunity(ID opportunityId){ if(opportunityId == null) { return null; } List<Opportunity> opps = [SELECT id, Opportunity.FTEs__c, Opportunity.Account.Industry , Opportunity.TotalNumberofSeats__c , Opportunity.CAPEX_Required__c , Opportunity.Amount , Opportunity.Annualized_Revenue__c, Opportunity.ProgramStartDate__c , Opportunity.Name FROM Opportunity WHERE Id =: opportunityId]; if(opps.size()>0){ return opps[0]; } return null; } }
I would appreciate any assistance. Thank you in advance.
Robert
All Answers
if($A.util.isEmpty(idOpp)) should be if(!$A.util.isEmpty(idOpp)). I mean if not empty then apex action should be called.