Clicking on Lightning button,I have to call visual force page dynamically based on record Id..how to do that ...onclick of button how to pass the perticular employee Id?

      <aura:component controller="AlloactionController" implements="force:appHostable,force:lightningQuickAction,flexipage:availableForRecordHome,flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
<aura:attribute name="isdisplay" type="boolean" default="false"/>
<aura:attribute name="emplst" type="Employee__c[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<table  class="slds-table slds-table--bordered slds-table--cell-buffer">
    <th class="head"> employee Id</th>
    <th class="head"> FBP allocation</th>
    <th class="head">TotalFBPallocation</th>
    <aura:iteration items="{!emplst}" var="employee"/>
        <td  class="cell">
            <ui:inputText Value="{!v.employee.Id}"/>
        <td  class="cell">
            <ui:inputText Value="{!v.employee.FBP_Allocation_Limit_per_Year__c}"/></td>
        <td  class="cell"><ui:inputText Value="{!v.employee.Total_FBP_Allocations_This_Year__c }"/></td>
        <td  class="cell"> <lightning:button label="FBP Allocation" onclick="{!c.VfpageCall}" id="{!employee.Id}" /></td>

    alert('@@@calling @@@');
    var action=component.get("c.fbpallocationDetails");
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            alert("From server: " + response.getReturnValue());
 VfpageCall : function(component, event, helper) {
    var myId = 'a0O6F00000mZKTW'; /

    var vfUrl = 'https://empowerhrms-dev-ed--c.ap4.visual.force.com/apex/FBPallocation?Id='+myId;
    var urlEvent = $A.get("e.force:navigateToURL");
        "url": vfUrl



***// I want ID DYNAMICALLY dynamically based on fbp alloaction button click

//suppose 5rows are there ..user clicked on 3rd row.I want that Id in javascript side [3rd row id]***

 public class AlloactionController {
public static List<Employee__c> fbpallocationDetails(){
    List<Employee__c> employeList=new  List<Employee__c>();
    employeList=[select id,FBP_Allocation_Limit_per_Year__c,Total_FBP_Allocations_This_Year__c from Employee__c];
    system.debug('employeelist================>'+ employeList);
    return employeList;



Keep your {!employee.Id} in your name attribute instead of id of lightning:button.

<lightning:button label="FBP Allocation" onclick="{!c.VfpageCall}" name="{!employee.Id}" />

Get the Id in your VfPageCall function,

var myId = event.getSource().get('v.name');

If you are using the component inside one/one.app, you can use this:

        var vfUrl = 'https://myinstance.visual.force.com/apex/MyVFPage?Id='+myId;
        var urlEvent = $A.get("e.force:navigateToURL");
          "url": vfUrl

Or if you are using the component any other place where one/one.app is not available, you can use this:

window.parent.location =vfUrl;
  • Thank you..but How can I open visual force page based on Id ..please check above code
    – user44385
    Apr 26 '17 at 9:47
  • Updated my answer. You can concatenate your Id with the URL. Apr 26 '17 at 10:27
  • Thank you ..you are right..how to pass Id dynamically can you please tell me..var myID what are you doing I want that value dynamically
    – user44385
    Apr 26 '17 at 10:49
  • Please check my updated code
    – user44385
    Apr 26 '17 at 10:55
  • Oh dear! You have to fetch the Id from the variable/attribute where you have kept it. I have updated my code assuming you have a attribute to store the Id or you want to fetch from the List. We expect you would use your intelligence on whatever help we provide. Apr 26 '17 at 11:12

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.