You need to sign in to do that
Don't have an account?
Warjie
Passing parameters to Custom Links via Apex
Hi, I come across a need to fill this requirement.
1. Create a custom Link that will redirect users to a custom report - DONE
2. Apex code to pass the parameter for the report to the custom link
Can anybody give me an idea how to do step #2?
Thanks :)
1. Create a custom Link that will redirect users to a custom report - DONE
2. Apex code to pass the parameter for the report to the custom link
Can anybody give me an idea how to do step #2?
Thanks :)
pv0 is the parameter for filter condition in report. make sure in your report, filter condition is equal to null. throught apex code we will pass value for it.use this based on your requirement.
if(Type == 'Projects'){
window.open('/{!$Label.ProjectReportID}?pv0='+PathValue);
} else
{
//error meaasge...
}
Thanks for the swift response. This is how I pass the values to the custom label in my method:
string url = '/{!$Label.HEIMS_Label}?pv0=' + euosToReport;
return new PageReference(url);
Note:
- euosToReport = values to pass
- HEIMS_Label = custom label containing the report Id
However, I get a URL No Longer exists issue whenever the method runs. I think I'm passing it incorrectly.
- store the report Id to a custom label together with the value needed (OK)
- pass this updated custom label to the custom link I made in the Home tab
NOTE: I don't want them to be redirected after code execution. I just made it to redirect for testing purposes so my previous answer can be disregarded. :)
Use onclick attribute in command link tag in VF page and call script function. in script you need to use window.open method for new tab, return report URL.
Refere the below code. and also see "OpenReportWindow" script function.
<apex:page controller="AutocpmpleteCon">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/jquery-1.8.2.js"></script>
<script src="https://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/>
<style>
.ui-autocomplete{
overflow: auto;
height: 300px;
}
</style>
<apex:form >
<apex:pageblock id="pb">
<apex:pageBlockSection title="View Reports" id="pbs" columns="3" collapsible="false">
<apex:outputLabel value="View Projects By" for="Projectid" styleclass="labelCol" style="font-size:100%"/>
<input type="text" id="Projectid"/>
<apex:commandButton value="View Report" id="pjbtn" onclick="OpenReportWindow('Projectid','Projects');return false;"/>
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="View Status By" for="statusid" styleclass="labelCol" style="font-size:100%"/>
<input type="text" id="statusid"/>
<apex:commandButton value="View Report" id="sbtn" onclick="OpenReportWindow('statusid','Status');return false;"/>
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="View Mill By" for="millid" styleclass="labelCol" style="font-size:100%"/>
<input type="text" id="millid"/>
<apex:commandButton value="View Report" id="mbtn" onclick="OpenReportWindow('millid','Mill');return false;"/>
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="View Designer By" for="designerid" styleclass="labelCol" style="font-size:100%"/>
<input type="text" id="designerid"/>
<apex:commandButton value="View Report" id="dbtn" onclick="OpenReportWindow('designerid','Designer');return false;"/>
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="View Purchaser By" for="purchaserid" styleclass="labelCol" style="font-size:100%"/>
<input type="text" id="purchaserid"/>
<apex:commandButton value="View Report" id="pbtn" onclick="OpenReportWindow('purchaserid','Purchaser');return false;"/>
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="View Agent To Purchaser By" for="AgentPurchaserid" styleclass="labelCol" style="font-size:100%"/>
<input type="text" id="AgentPurchaserid"/>
<apex:commandButton value="View Report" id="atodpbtn" onclick="OpenReportWindow('AgentPurchaserid','AToPurchaser');return false;"/>
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="" />
<apex:outputLabel value="View Agent To Designer By" for="AgentDesignerid" styleclass="labelCol" style="font-size:100%"/>
<input type="text" id="AgentDesignerid"/>
<apex:commandButton value="View Report" id="atoppbtn" onclick="OpenReportWindow('AgentDesignerid','AToDesigner');return false;"/>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
<script type="text/javascript">
//Create a new variable j$ just to avoid any conflicts with other libraries which may be using $.
var j$ = jQuery.noConflict();
//on Document ready
var lstProject =[];
<apex:repeat value="{!lstOpps}" var="Opp">
var elem = "{!Opp.Name}";
lstProject.push(elem.replace(/[^\w\s]/gi, ''));
</apex:repeat>
console.log(lstProject);
j$(document).ready(function(){
j$("#Projectid").autocomplete({
source : lstProject,
minLength: 0
});
});
// Autocomplete for status
var lstStatus =[];
<apex:repeat value="{!lstOppsStatus}" var="Opp">
var elem = "{!Opp.Status__c}";
lstStatus.push(elem.replace(/[^\w\s]/gi, ''));
</apex:repeat>
j$(document).ready(function(){
j$("#statusid").autocomplete({
source : lstStatus,
minLength: 0
});
});
// Autocomplete for Mill
var lstMill =[];
<apex:repeat value="{!lstMills}" var="mil">
var elem = "{!mil.name}";
lstMill.push(elem.replace(/[^\w\s]/gi, ''));
</apex:repeat>
j$(document).ready(function(){
j$("#millid").autocomplete({
source : lstMill,
minLength: 0
});
});
// Autocomplete for Designer
var lstDesigner =[];
<apex:repeat value="{!lstAcc}" var="Acc">
var elem = "{!Acc.name}";
lstDesigner.push(elem.replace(/[^\w\s]/gi, ''));
</apex:repeat>
j$(document).ready(function(){
j$("#designerid").autocomplete({
source : lstDesigner,
minLength: 0
});
});
// Autocomplete for Purchaser
var lstPurchaser =[];
<apex:repeat value="{!lstAcc}" var="Acc">
var elem = "{!Acc.name}";
lstPurchaser.push(elem.replace(/[^\w\s]/gi, ''));
</apex:repeat>
j$(document).ready(function(){
j$("#purchaserid").autocomplete({
source : lstPurchaser,
minLength: 0
});
});
// Autocomplete for Agent To Purchaser
var lstAgentPurchaser =[];
<apex:repeat value="{!lstCon}" var="con">
var elem = "{!con.name}";
lstAgentPurchaser.push(elem.replace(/[^\w\s]/gi, ''));
</apex:repeat>
j$(document).ready(function(){
j$("#AgentPurchaserid").autocomplete({
source : lstAgentPurchaser,
minLength: 0
});
});
// Autocomplete for Agent To Designer
var lstAgentDesigner =[];
<apex:repeat value="{!lstCon}" var="con">
var elem = "{!con.name}";
lstAgentDesigner.push(elem.replace(/[^\w\s]/gi, ''));
</apex:repeat>
j$(document).ready(function(){
j$("#AgentDesignerid").autocomplete({
source : lstAgentDesigner,
minLength: 0
});
});
function OpenReportWindow(val,Type){
var PathValue = document.getElementById(val).value;
if(Type == 'Mill'){
if(PathValue != ''){
window.open('/{!$Label.MILLReportID}?pv0='+PathValue);
}else{
alert('There are no Mill to View the report');
}
}else if(Type == 'Status'){
if(PathValue != ''){
window.open('/{!$Label.StatusReportId}?pv0='+PathValue);
}else{
alert('There are no Status to View the report');
}
}else if(Type == 'Projects'){
if(PathValue != ''){
window.open('/{!$Label.ProjectReportID}?pv0='+PathValue);
}else{
alert('There are no Projects to View the report');
}
}else if(Type == 'Designer'){
if(PathValue != ''){
window.open('/{!$Label.DesignerReportId}?pv0='+PathValue);
}else{
alert('There are no Designer to View the report');
}
}else if(Type == 'Purchaser'){
if(PathValue != ''){
window.open('/{!$Label.PurChanserReportId}?pv0='+PathValue);
}else{
alert('There are no Purchaser to View the report');
}
}else if(Type == 'AToPurchaser'){
if(PathValue != ''){
window.open('/{!$Label.AgentToPurchaser}?pv0='+PathValue);
}else{
alert('There are no Agent To Purchaser to View the report');
}
}else if(Type == 'AToDesigner'){
if(PathValue != ''){
window.open('/{!$Label.AgentToDesignerId}?pv0='+PathValue);
}else{
alert('There are no Agent To Designer to View the report');
}
}
}
</script>
</apex:page>