Display report in visualforce page - salesforce

i want to display a report on a visualforce page. I found this snippet of code but it brings back a blank page. What piece am i missing to have it show the report data?
<apex:page showHeader="false" sidebar="false">
<apex:iframe src="/00OQ0000000Gdbm"/>
</apex:page>

I use code that looks like this to show a report in a Visualforce page. I've left out details that would get in the way:
<apex:page standardController="CustomOb__c" extensions="CobjController">
<apex:sectionHeader title="Manage Stuff"/>
<apex:form>
...
<apex:outputPanel id="MissingAttRpt" >
<apex:iframe src="/00O0000000AAJlV?isdtp=lt" scrolling="true" height="1588px" width="100%"/>
</apex:outputPanel>
...
</apex:form>
</apex:page>
The outputPanel is used so that the report can be re-rendered without refreshing the whole page.
Try getting rid of the showHeader and sidebar properties.

Related

Refresh Record Page with Apex via a Visualforce Page

I want to create a button that effectively does the same thing as "ctrl r"
After my end user finishes updating info in the visualforce page. I want to give them to option to click this button and it will refresh the entire record page which the visualforce is embedded onto.
I honestly have no idea how to do this, my coding experience is limited. The only thing i've been able to do is get the page to reload within the visualforce page and that's not very helpful.
This is what I tried:
Visualforce code:
<apex:page standardController="Request__c" extensions="ActionRelatedList">
<apex:form>
<apex:pageBlock>
<apex:commandButton value="Reload" action="{!redirect}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Redirect method:
public PageReference redirect() {
String requestURL ='URL';
PageReference newRequestURL = new PageReference(requestURL);
newRequestURL.setRedirect(true);
return newRequestURL;
}
But this doesn't refresh my entire page, it just opens it within the visualforce page.
You can do this using code below:
<apex:page standardController="Account" >
<apex:form >
<apex:pageBlock>
<apex:commandButton value="Reload" onclick="window.top.location='/{!Account.id}'; "/>
</apex:pageBlock>
</apex:form>
</apex:page>

ActionFunction won't call controller function without Alert Message

I'm trying to capture the selected tab in my controller. I have the below code and it works fine if I leave in the alert message in the script. Once I remove the alert it no longer seems to make the call to the controller. I'm only displaying one tab in the code snippet. I have 3 others defined.
<apex:page showheader="true" sidebar="true" controller="mycontroller">
<script>
function setActiveTabJava(value){
alert('here');
setActiveTab(value);
}
</script>
<apex:form >
<apex:actionFunction id="activeTab" name="setActiveTab" action="{!setTab}" reRender="">
<apex:param name="activeTab" assignTo="{!activeTab}" value=""/>
</apex:actionFunction>
</apex:form>
<apex:pageblock >
<apex:tabpanel selectedtab="Tab One" width="100%">
<apex:tab label="This is tab one" name="tabone" id="referralTab" ontabenter="setActTabJava('TAB1');">
<!-- other tab code-->
</apex:tab>
</apex:tabpanel>
</apex:pageblock>
I basically fixed this by using the value attribute on the tab panel. Since my controller only interested in know which tab was selected, and not when the tab was selected it worked. Basically:
<apex:tabpanel value="{!activeTab}">
<apex:tab name="tab1">...</apex:Tab>
So whenever a tab is changed, as long as you've specified a name attribute on the tab it will be accessible in your controller.
So sorry I no longer have that controller code to post but it was basically just a method that set a variable in the controller.

Visualforce Apex:pageMessages validation rule Issue

I have custom validation rules defined on my custom employee__c object in salesforce. I use a standard controller visualforce page with custom extension to show a UI to the user for data entry. My challenge is to show the validation rule error to the user in an easy to read manner. Here is the part of the code that I have.
Visualforce
<apex:page standardController="Employee__c" extensions="EmployeeExtension" sidebar="false">
<apex:sectionHeader ...
<apex:form id=fr>
<apex:pageMessages id="errMsg"/>
<apex:pageBlock title="Employee Edit" mode="edit" >
<apex:pageBlockButtons >
<apex:commandButton action="{!mySave}" value="Save" reRender="errMsg"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
....
</apex:form>
</apex:page>
Apex Controller
public class EmployeeExtension {
....
public PageReference mySave(){
....
try{
upsert empList;
} catch (DMLException ex) {
ApexPages.addMessages(ex);
}
}
}
This shows the errors at the page top which is the way I want, but it shows twice. Here is how it will display the error at page top.
error_message_from_custom_validation_comes_here
TriggerEmployee: Exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, error_message_from_custom_validation_comes_here
In my entire controller I do not have any other DML operations nor do I use ApexPages.addmessage any where else. The strange thing is if I remove
ApexPages.addMessages(ex);
while keeping the try catch block as is, then I see only
error_message_from_custom_validation_comes_here
I wonder why it shows the page messages in vf page even when I am not sending anything from controller. I appreciate all your responses, but I would like to see solutions not involving javascript or jquery.
You can use this:
ApexPages.addMessage(
new ApexPages.Message(
ApexPages.severity.ERROR,
ex.getMessage()
)
);
Alternatively you could also imitate the standardController:
public class EmployeeExtension {
....
public PageReference mySave(){
/* do your thing */
return this.standardController.save();
}
}
This way you return the page reference of the save which is the standard behaviour (if you want to imitate this) and if there is a validation error it will show up in the tag and only the nice formatted message will show up.
You don't need a reRender on the save:
<apex:page standardController="Employee__c" extensions="EmployeeExtension" sidebar="false">
<apex:sectionHeader ...
<apex:form id=fr>
<apex:pageMessages/>
<apex:pageBlock title="Employee Edit" mode="edit" >
<apex:pageBlockButtons >
<apex:commandButton action="{!mySave}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
....
</apex:form>
</apex:page>
Salesforce/Visualforce will do the rest for you :)

How to remove the hyperLink for Case Owner field in an inline VF page?

Lets say i have an inline VF page
Code Snippet
<apex:page>
<apex:pageBlockTable value="{!tempList}" var="c" width="100%" columns="11">
<apex:column value="{!c.OwnerId}" headerValue="Case Owner">
</apex:column>
</apex:pageBlocktable>
</apex:page>
From the contrioller i get the tempList (List created on Case).
Now in the inline VF page i want to remove the hyper link for the case owner name that got displayed in my page.
Any Thoughts ?
<apex:column value="{!c.Owner.Name}" headerValue="Case Owner" />

reRender and rendered attribute in visualforce

i write a visualforce page with source code
<apex:page controller="MyController1">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="search">
<apex:commandLink action="{!commandLinkAction}" value="Advance Search" reRender="thePanel" id="theCommandLink"/>
<apex:outputPanel id="thePanelWrapper">
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">My div</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
and the MyController1 class is
public class MyController1{
public Boolean rend{get;set;}
public PageReference commandLinkAction(){
rend=true;
return null;
}
}
when i click on Advanced Search link nothing happens but i was expecting outputPanel with id "thePanel" should render.why it is not rendering please someone explain??
In moment that you click on the link the panel not on the page, SF not rendered it.
As #Shimshon said, when the HTML code is generated from Visualforce, the Visualforce components marked as rendered="false" are not displayed in the resulting HTML document.
In this case:
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">
if you are going to rerender this panel, then you must ensure that the component will be displayed in the HTML code so the rerender action can find it. Since {! rend} is initially set to false in the controller's constructor "thePanel" is never rendered in the page, thus you try to rerender a component that does not exist.
#theGreatDanton 's solution will work because <apex:outputPanel id="thePanelWrapper"> is the container panel that is always rendered:
<apex:commandLink action="{!commandLinkAction}" value="Advance Search" reRender="thePanelWrapper" id="theCommandLink"/>
and if this panel is pointed by rerender attribute, then "thePanelWrapper" and their child nodes ("thePanel") will be updated.
try the below code.
<apex:page controller="MyController1">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="search">
<apex:commandLink action="{!commandLinkAction}" value="Advance Search" reRender="thePanelWrapper" id="theCommandLink"/>
<apex:outputPanel id="thePanelWrapper">
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">My div</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class MyController1{
public Boolean rend{get;set;}
//setting the boolean to false in the constructor
public MyController1(){
rend = false;
}
public void commandLinkAction(){
rend=true;
// return null;
}
}
Hope this helps!!

Resources