Friday, January 30, 2015

Visualforce PDF Rendering Considerations and Limitations

Visualforce PDF Rendering Considerations and Limitations
                       OR
RenderasPDF considerations in visualforce

Limitations of the Visualforce PDF rendering service include:


  • PDF is the only supported rendering service.
  • Rendering a Visualforce page as a PDF is intended for pages designed and optimized for print.
  • Standard components that aren’t easily formatted for print, or form elements like inputs, buttons, or any component that requires JavaScript to be formatted, shouldn’t be used. This includes, but isn’t limited to, any component that requires a form element.
  • PDF rendering doesn’t support JavaScript-rendered content.
  • Font used on the page must be available on the Visualforce PDF rendering service. Web fonts aren’t supported.
  • If the PDF fails to display all of the page’s text, particularly multi-byte characters such as Japanese or accented international characters, adjust the fonts in your CSS to use a font that supports them. For example:
  • Arial Unicode MS” is currently the only font supported for extended character sets that include multi-byte characters.
  • If you use inline CSS styles, you must set the API version to 28.0 or greater, set <apex:page applyBodyTag="false">, and add static, valid<head> and <body> tags to your page, as in the example above.
  • The maximum response size when creating a PDF must be below 15 MB before being rendered as a PDF. This is the standard limit for all Visualforcerequests.
  • The maximum file size for a generated PDF is 60 MB.
  • The maximum total size of all images included in a generated PDF is 30 MB.
  • PDF rendering doesn’t support images encoded in the data: URI scheme format.
  • Note that the following components do not support double-byte fonts when rendered as a PDF:
    • <apex:pageBlock>
    • <apex:sectionHeader

                These components aren’t recommended for use in pages rendered as a PDF.







Thursday, January 29, 2015

What are @Featuremethod Considerations?

What are @Featuremethod Considerations?

Methods with the future annotation must be static methods, and can only return a void type. The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types. Methods with the future annotation cannot take sObjects or objects as arguments.


  • Specify (callout=true) to allow callouts in a future method. 
  • Specify (callout=false) to prevent a method from making callouts.


@future (callout=true)
  public static void doCalloutFromFuture() {
   //Add code to perform callout
}


  • Remember that any method using the future annotation requires special consideration because the method does not necessarily execute in the same order it is called.
  • Methods with the future annotation cannot be used in Visualforce controllers in either getMethodName or setMethodName methods, nor in the constructor.
  • You cannot call a method annotated with future from a method that also has the future annotation. Nor can you call a trigger from an annotated method that calls another annotated method.
  • The getContent and getContentAsPDFPageReference methods cannot be used in methods with the future annotation.





Wednesday, January 28, 2015

What is difference between Action function and remote function?

What is difference between Action function and remote function?

1. Using action function, you can call only same class function.
2. Remote Action returns the results from the class in Javascript.
3. Action function submit the page, Remote action doesn't

Remote Action in Visual force page:
JavaScript remoting in Visualforce provides support for some methods in Apex controllers to be called via JavaScript.

• namespace is your organization's namespace. This is only required if the class comes from an installed packaged.
• controller is the name of your Apex controller- MyJSControllers
• method is the name of the Apex method you're calling- getAccount
• params is comma–separated list of parameters that your method takes-accountNameJS
• callbackFunction is the name of the function that handles the response from the controller. It returns the status of the call and the method result.- function
• escape defines whether your response should be escaped (by default, true) or not (false)- {escape:true}

·    JavaScript remoting:
- pass parameters
- provides a callback
·        The <apex:actionFunction> tag:
- specify rerender targets
- submits the form



Monday, January 26, 2015

Pros and Cons of Choosing Pagination in Salesforce.

Pros and Cons of Choosing Pagination in Salesforce.

Visualforce StandardSetController


The StandardSetController is an extremely powerful tool with built-in functionality that you can use to greatly simplify the custom code in your Visualforce pages. Because the server returns only the data for the page being requested, the StandardSetController can significantly reduce view state, especially compared to the view state you would get while using SOQL.

Pros
· Manages data sets on the server, which reduces page state and increases performance
·  Allows you to paginate over large data sets that have up to 10,000 records
·  Includes built-in functionality such as next, previous, first, last, getResultSize, and other methods that can simplify your page
·  Allows you to paginate forward and backward or to any page within the result set
·  Uses a server-side cursor to cache the entire result set, so results will not change if data changes in the database while a user is paginating from one page to the next

Cons

·  Has built-in functionality that results in a very small increase in view state size
·  Can be used only in Apex
You can find more information about StandardSetController in our Visualforce documentation here.

Example: Retrieving Data in Apex to Paginate with the StandardSetController

public class opportunityList {
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Name, StageName, Amount, Account.Name, Account.Named_Account__c FROM Opportunity where Account.BillingState = ‘California’ and Status__c = ‘Open’]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
    public List getOpportunities() {
        return (List) setCon.getRecords();
    }
}


OFFSET Clauses within SOQL Queries


With Salesforce SOQL, you can add an OFFSET clause, as well as a limit specifying a start point and a range of records to retrieve for a page, within your queries. This functionality allows you to implement your own pagination with SOQL queries without having to store the entire data set in memory. As a user moves from one page to the next, each page request executes a query to return the specific records required for that page.
Pros
·  Can be used in SOQL executed within the SOAP API, the REST API, or Apex
·  Gives you the ability to build robust pagination using the Force.com APIs without having to store the entire data set in the Web application
Cons
· Supports OFFSET clauses only for ranges of 2,000 or fewer records
· No server-side cursor is created to cache the full result set for future OFFSET queries. This means that what you see in each page of results reflects what is in the database at the time that you submitted your request. So if someone modifies the underlying data while you're paginating over large data sets, what you saw in the previous or following pages might have changed.
·  As users move from one page the next in the result set, each of their requests for page results executes a query against the database.
· If you want to build advanced pagination functionality that displays a specific number of result pages, you must use a SOQL query to retrieve the total number of records before you execute the query containing the OFFSET clause. Executing this SOQL query to count the records affects performance and limits usage.

While many developers view OFFSET as the tool of choice for pagination, we will see that there are many cases in which it is not the tool of choice from a performance perspective.

To read more about OFFSET, see its Force.com SOQL and SOSL Reference topichere.

Example: Retrieving Data With OFFSET to build Custom Pagination

This query returns the first 25 records of our result set.

SELECT Name, StageName, Amount, Account.Name,
 Account.Named_Account__c 
  FROM Opportunity 
 WHERE Account.BillingState = ‘California’
   AND Status__c = ‘Open’
 ORDER BY Account.Name
 LIMIT 25
OFFSET 0

When the user selects the next page in the result set, this query returns the next set of 25 records.

SELECT Name, StageName, Amount, Account.Name, 
Account.Named_Account__c 
  FROM Opportunity 
 WHERE Account.BillingState = ‘California’ and Status__c = ‘Open’
 ORDER BY Account.Name
 LIMIT 25
OFFSET 25








Sunday, January 25, 2015

How to Use Apex:enhancedList tag in Visualforce Page?

How to Use Apex:enhancedList tag in Visualforce Page?

Enhanced list views on a Visualforce page

Enhanced lists are used when you want to display a specific list view for a standard or custom object, rather than having all list views available for the user to select.

This tag supports following attributes.

Attribute Name
Description
customizable
A Boolean value that specifies whether the list can be customized by the current user. If not specified, the default value is true. If this attribute is set to false, the current user will not be able to edit the list definition or change the list name, filter criteria, columns displayed, column order, or visibility. However, the current user's personal preferences can still be set, such as column width or sort order.
height
An integer value that specifies the height of the list in pixels. This value is required.

id
The database ID of the desired list view. When editing a list view definition, this ID is the 15-character string after 'fcf=' in the browser's address bar. This value is required if type is not specified.
listId
The Salesforce object for which views are displayed. This value is required if type is not specified.
oncomplete
The JavaScript that runs after the page is refreshed in the browser. Note that refreshing the page automatically calls this JavaScript, while an inline edit and subsequent save does not.
rendered
A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
reRender
The ID of one or more components that are redrawn when the result of an AJAX update request returns to the client. This value can be a single ID, a comma-separated list of IDs, or a merge field expression for a list or collection of IDs. Note: When an enhancedList is rerendered through another component's rerender attribute, the enhanceList must be inside of an apex:outputPanel component that has layout attribute set to "block".
rowsPerPage
An integer value that specifies the number of rows per page. The default value is the preference of the current user. Possible values are 10, 25, 50, 100, 200. Note: If you set the value for greater than 100, a message is automatically displayed to the user, warning of the potential for performance degradation.
type
The Salesforce object for which views are displayed, for example, type="Account" or type="My_Custom_Object__c".
width
An integer value that specifies the width of the list in pixels. The default value is the available page width, or the width of the browser if the list is not displayed in the initially viewable area of the viewport.



Step 1 – Create the list view

Go to the standard or custom object and click on the Create New View next to the Go button. Create the view and click on Save. When the page has reloaded, you will notice in the url a 15 digit id has been created for your view. Copy or make a note of the id.






Step 2 – Add code to your visualforce page

Add the following bit of code to your visualforce page, replacing the listid with your id:


<apex:enhancedlist type=”Lead” height=”730″ customizable=”false” rowsPerPage=”25″ Listid=”00B30000007wesH” />

Change customizable to equal true if you want your users to be able to edit the filters on the view. Once saved, you should find your visualforce page displays an enhanced list similar in appearance to the image below.





More about Visualforce page Tags:
http://sfdcsrini.blogspot.com/2014/06/visualforce-form-tags-with-examples.html

I have requirement fire the trigger when data is uploading through data loader. It should not execute when record saved from User interface? How to achieve that?

I have requirement fire the trigger when data is uploading through data loader. It should not execute when record saved from User interface? How to achieve that?



You could add a custom checkbox field which is hidden from the pagelayout.
· This field could be mapped to always insert as "true" with dataloader.
· Make your after insert trigger only execute conditionally on this field to be true.

· Optionally have your trigger set the field to false, or you could keep it as true to see that these records were imported through data loader.



How to Use Apex:listViews tag in Visualforce Page?

How to Use Apex:listViews tag in Visualforce Page?


The list view picklist for an object, including its associated list of records for the currently selected view. In standard Salesforce applications this component is displayed on the main tab for a particular object.


This tag supports following attributes.

Attribute Name
Description
id
An identifier that allows the listViews component to be referenced by other components in the page.
rendered
A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.

type
The Salesforce object for which list views are displayed, for example, type="Account" or type="My_Custom_Object__c".



Facet Name
Description
body
The components that should appear in the body of the displayed list of records. Note that the order in which a body facet appears in a listViews component does not matter, because any facet with name="body" will control the appearance of the body of the displayed list. Also note that if you define a body facet, it replaces the list of records that would normally display as part of the list view.
footer
The components that should appear in the footer of the displayed list of records. Note that the order in which a footer facet appears in the body of a listViews component does not matter, because any facet with name="footer" will control the appearance of the bottom of the displayed list.
header
The components that should appear in the header of the displayed list of records. Note that the order in which a header facet appears in the body of a listViews component does not matter, because any facet with name="header" will control the appearance of the top of the displayed list.



 Example:

<apex:page showHeader="true" tabstyle="Case">
    <apex:ListViews type="Case" />
    <apex:ListViews type="Member__c" />
</apex:page>







More about Visualforce Tags :
http://sfdcsrini.blogspot.com/2014/06/visualforce-form-tags-with-examples.html


How to Use Apex:relatedList tag in Visualforce Page?

How to Use Apex:relatedList tag in Visualforce Page?


It is going to display a list of Salesforce records that are related to a parent record with a lookup or master-detail relationship.


This tag supports following attributes.

Attribute Name
Description
id
An identifier that allows the relatedList component to be referenced by other components in the page.
list
The related list to display. This does not need to be on an object's page layout. To specify this value, use the name of the child relationship to the related object. For example, to display the Contacts related list that would normally display on an account detail page, use list="Contacts".

pageSize
The number of records to display by default in the related list. If not specified, this value defaults to 5.
rendered
A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
subject
The parent record from which the data and related list definition are derived. If not specified, and if using a standard controller, this value is automatically set to the value of the ID query string parameter in the page URL.
title
The text displayed as the title of the related list. If not specified, this value defaults to the title specified in the application.


Facet Name
Description
body
The components that appear in the body of the related list. Note that the order in which a body facet appears in a relatedList component does not matter, because any facet with name="body" will control the appearance of the related list body. If specified, this facet overrides any other content in the related list tag.
footer
The components that appear in the footer area of the related list. Note that the order in which a footer facet appears in the body of a relatedList component does not matter, because any facet with name="footer" will control the appearance of the bottom of the related list.
header
The components that appear in the header area of the related list. Note that the order in which a header facet appears in the body of a relatedList component does not matter, because any facet with name="header" will control the appearance of the top of the related list.



Example :

<apex:page standardController="Account">
    <apex:pageBlock >
    You're looking at some related lists for {!account.name}:
    </apex:pageBlock>

    <apex:relatedList list="Opportunities" />

    <apex:relatedList list="Contacts">
        <apex:facet name="header">Titles can be overriden with facets</apex:facet>
    </apex:relatedList>

    <apex:relatedList list="Cases" title="Or you can keep the image, but change the text" />
</apex:page>


Pass the account id as url parameter to display the related list.
For example, if 001D000000IRt53 is the account ID, the resulting URL should be:
https://Salesforce_instance/apex/myPage?id=001D000000IRt53






More about Visualforce Tags Examples:

How to Use Apex:SectionHeader tag in Visualforce Page?

How to Use Apex:SectionHeader tag in Visualforce Page?


A title bar for a page. In a standard Salesforce page, the title bar is a colored header displayed directly under the tab bar.


This component supports HTML pass-through attributes using the "html-" prefix. Pass-through attributes are attached to the generated container <div> tag.


This tag supports following attributes.

Attribute Name
Description
description
Descriptive text for the page that displays just under the colored title bar.
help
A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
id
An identifier that allows the sectionHeader component to be referenced by other components in the page.
printUrl
The URL for the printable view.
rendered
A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
title
The text displayed at the top of the colored title bar.
subtitle
The text displayed just under the main title in the colored title bar.


Example:

<apex:page standardController="Opportunity" tabStyle="Opportunity" sidebar="false">
    <apex:sectionHeader title="One of Your Opportunities" subtitle="Exciting !"/>
    <apex:detail subject="{!opportunity.id}" relatedList="false" title="false"/>

</apex:page>








 
| ,