Showing posts with label Visualforce. Show all posts
Showing posts with label Visualforce. Show all posts

Friday, 5 August 2016

Salesforce Header and Sidebar is not displaying in visualforce Page

To resolve this issue, if you see inline=1 in the URL of the visualforce page, then that is the reason for the header and sidebar is not displayed.

To  resolve this issue, please use this below script in the visualforce page to display the sidebar and header.

<script>

if (location.href.match(/inline=1/)) window.top.location=location.href.replace(/inline=1/, '');
</script>

Friday, 29 July 2016

On Click on apex:outputText Tag.


Lets see how to use onclick on the <apex:outputText> Tag.

Its very simple, but it took 3 hours to find the solution for it.

Here you go,

Its just a simple code on Account Object.

VF Page

<apex:page standardController="Account" extensions="outputfielddblclick_extn" id="pg1">
<apex:form id="frm1" >
<apex:pageBlock id="pb1">
<apex:pageBlockSection id="pbs1" >
<apex:outputpanel id="counter">
<table>
 <tr>
<td> <apex:outputText value="Account Name"></apex:outputText> </td>
<td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td>                 
<td> <apex:outputText value="{!Account.Name}"/>
<apex:actionSupport event="ondblclick" action="{!justdisplay}" rerender="counter" status="s1"/>        <!-- Status is not a mandatory -->
</td>
</tr>
</table>
</apex:outputpanel> 
<apex:actionStatus id="s1"> <!-- This status is used in the actionSupport. Its not mandatory -->
<apex:facet name="start">
loading....
</apex:facet>
</apex:actionStatus>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Below is the apex class,

public class outputfielddblclick_extn {

    public outputfielddblclick_extn(ApexPages.StandardController controller) {

    }
    public void justdisplay()
    {
        system.debug('RRRRRRRRInside FunctionRRRRRRRR');
        // your logic here
    }
}

If you double click on the Account Name, it will call the "justdisplay()" method in the class.

Below is the output screen.


It will work on apex:outputfield also.

Happy Coding!!!

Sunday, 19 January 2014

Add Visualforce page in Message and Alert Section of the Home Page.

Step 1:
Create a Visualforce Page.


Step 2: In the Home Page Components, click edit on Message and Alert Section

Enter the below code in that section.

Output:


Tuesday, 3 December 2013

Creating Excel in Visualforce Page.

Create a visualforce page and add the content type attribute in the <apex:page>

<apex:page standardController="Opportunity" extensions="OpportunityReport_Extn" showHeader="true" sidebar="true" cache="true" contenttype="application/vnd.ms-excel#Opportunity_report.xls">
  <apex:pageBlock >
       <apex:pageblockTable value="{!generateReport}" var="oppty" id="tbl1">
           <apex:column value="{!oppty.Name}"/>
           <apex:column value="{!oppty.Id}"/>
           <apex:column value="{!oppty.StageName}"/>
           <apex:column value="{!oppty.Closedate}"/>
           <apex:column value="{!oppty.Type}" />
       </apex:pageblockTable>    
   </apex:pageBlock>
</apex:page>

In this page I have used controller, below is the code for that.

public class OpportunityReport_Extn {
    public List <Opportunity> getgenerateReport()
    {
       query = 'select Closedate,Name,Type,StageName,Id from Opportunity';    
        try
        {
            List<Opportunity> opplist = database.query(query);
            return opplist;          
        }
        catch (QueryException e)
        {
            ApexPages.addMessages(e);
            return Null;
        }      
   }
}

The above code will generate the Excel sheet.

Note: If your excel sheet contains some extra data, such us Months and month picklist, for that if you have used <apex:form> tag, remove that form tag in the visualforce page.

Wednesday, 6 November 2013

View state in Visualforce page

View state will get generated when we use<apex:form> tag not on HTML <form> tag.

Below is the list of tag where <apex:form> tag is required.

<apex:action*>
<apex:Command*>
<apex:InlineEditSupport>
<apex:Input*>
<apex:Select*>

How to Manage View State in Visualforce page.

  1. Reduce Number of Components
  2. Transient Keyword
  3. Java Script Remoting
  4. Streaming API.

Reduce the Number of Components:


using of pageblock table and pageblocks is fine, which will look simillar to salesforce user Interface, but try to avoid some below component instead you use HTML tags.

<apex:OutputPanel Layout="inline".... >          <span>
<apex:outputpanel layout ="block".....>          <div>
<apex:panelGrid.... >                                     <table>
<apex:outputlink....>                                      <a>
<apex:outputtext styleclass="".....>                 <span>

Transient Keyword


If the declared variable is going to display the values in the visualforce page then we can use Transient Keyword with that variable. It will reduce the view state.

Example

VF code:

<apex:page controller="TranController"  showHeader="false"
standardStylesheets="false">
 <apex:pageBlock >
<apex:pageBlockButtons location="top">
                    <apex:commandButton action="{!save}" value="Save"/>
 </apex:pageBlockButtons>
<apex:pageBlockSection columns="2">
                    <apex:inputField value="{!client.FirstName}"/>
                    <apex:inputField value="{!client.LastName}"/>
                    <apex:inputField value="{!client.Email}"/>
                    <apex:inputField value="{!client.Phone}"/>
                    <apex:inputField value="{!client.MobilePhone}"/>
                    <apex:inputField value="{!client.MailingStreet}"/>
</apex:pageblocksection>
</apex:pageblock>
<h3>Previous Employers</h3>
            <apex:dataTable value="{!previousEmployers}" var="e">
                <apex:column value="{!e.Name}"/>
            </apex:dataTable>
</apex:page>

Apex Code:

public with sharing class TranController{
    public Contact client { get; private set; }
     transient public List<Account> previousEmployers { get; private set; }
 
    public TranController() {
        this.client = retrieveClient();
        this.previousEmployers = retrievePreviousEmployers();
}
private Contact retrieveClient() {
        return [
            SELECT
                 Phone,
                MobilePhone,
                MailingStreet,
                LastName,
                FirstName,
                Email,
               FROM Contact
            LIMIT 1
        ];
    }
private List<Account> retrievePreviousEmployers() {
        List<Account> a = new List<Account>();
        a.add(new Account(Name = 'GE'));
        a.add(new Account(Name = 'Siemens'));
        a.add(new Account(Name = 'EADS'));
        return a;
    }
 public void save() {
        try {
            insert client;
        } catch (Exception x) {
            client.addError(x.getMessage());
        }
    }
}

JavaScript Remoting


Stateless way to call Apex Controller Methods from Javascript.

instead of using <apex:actionfunction..../> and <apex:actionsupport..../> we can use javascript remoting.

Streaming API


A highly performant way to get near real time updates from a salesforce instance without polling.

instead of using <apex:action:poller..../> we can use streaming API.


The above 4 methods will reduce the view state of visualforce.




Monday, 4 November 2013

Detail Page Link in Visualforce Email Template

Below code is to display the record link in Visualforce Email Template,


{!LEFT($Api.Partner_Server_URL_140, FIND(".com/",$Api.Partner_Server_URL_140)+3)}/{!relatedTo.Id}"

Output


https://ap1.salesforce.com/0069000000DBDQm


Saturday, 26 October 2013

Format the Date field in visualforce and VF Email Template

Below is the code which is used to format the date in Visualforce page and VF Email Template

<apex:outputText value="{0,date,MM/dd/YYYY}">
    <apex:param value="{!relatedTo.closeDate}" />
</apex:outputText> </td>

Output:

08/11/2010