I want to be able to run 4 different queries on a single visualforce page depending on the button clicked on a lightning component. Right now the way its set up works but it can't access the static variable on the apex controller so the page is always blank. (This is going to be a table style query with multiple rows and columns)
My other thought process was to put all the queries in the constructor but then how do you set the variable from the lightning controller? I tried action.setParams({'detQ':'ten'})
but I guess im using the wrong syntax or this isn't feasible. (also tried 'c.detQ', detQ with no luck) and then the constructor would be automatically called when the class is invoked right?
Heres what I have so far.
Aura:
<aura:component controller="PropertyPDFController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
some stuff
<lightning:button
label="10%"
iconName="utility:open"
iconPosition="left"
variant="base"
type="submit"
onclick="{!c.ten}"
value="{!property.Id}"
/>
<lightning:button
label="25%"
iconName="utility:open"
iconPosition="left"
variant="base"
type="submit"
onclick="{!c.twentyFive}"
value="{!property.Id}"
/>
some stuff
</aura:component>
Controller
ten : function (component, event, helper)
{
//get value of invoked button
var myId = event.getSource().get('v.value');
//call method of controller
var action = component.get("c.DisplayAccounts");
//set variable equal to acc id
action.setParams({'propSearch': myId});
action.setCallback(this,function(response){
var state = response.getState();
if(state === "SUCCESS")
{
window.open('/apex/PropertyPDFViewer');
}
else{
console.log('unable to generate the pdf');
}
});
$A.enqueueAction(action);
},
Apex:
public class PropertyPDFController
{
@AuraEnabled
public String detQ;
public List<opportunity> hipdeals {get; set;}
public PropertyPDFController(ApexPages.StandardController controller)
{
hipdeals = new List<opportunity>();
//wondering if i can somehow set this value from lightning controller
detQ = '';
//then use if/else statements to run queries based on value
if(detQ == 'ten')
{
hipdeals = [select stuff];
} else
if(detQ==25)
{
do other stuff
}
}
//what i'm using right now
@AuraEnabled
public static List<Opportunity> DisplayAccounts(String propSearch)
{
system.debug(propSearch);
String secondSearch = propSearch;
List<opportunity> hipdeals = new List<opportunity>();
deals = [select stuff from opportunity};
//I cant access this variable from VFP even if its declared outside method
return deals;
}
VFP:
<apex:page StandardController="Opportunity" extensions="PropertyPDFController" applyBodyTag="false" sidebar="false" showHeader="false" renderAs="PDF">
<apex:repeat var="Deals" value="{!hipdeals}" id="theRepeat">
<tr>
<td>{!Deals.Ownership1__c}</td>
<td>{!Deals.HIP_Market__c}</td>
<td>{!Deals.Prop_Building_Name__r.name}</td>
<td>{!Deals.Name}</td>
<td>{!Deals.Probability}<ins>%</ins></td>
<td>
</apex:page>