Posts

Showing posts from January, 2017

Visualforce Pagination using SOQL Limit and Offset

Image
Using SOQL to Implement Pagination in Visualforce page Now we can implement pagination in visualforce pages, simple using the SOQL predefined clauses LIMIT and OFFSET. Here Limit is used to get the records and Offset is used to skip records. see the following example. Note: The maximum offset limit is 2,000 rows. Executing offset greater than 2,000 will result in a "NUMBER_OUTSIDE_VALID_RANGE" error. Visuaforce code for Pagination: <apex:page controller="SOQLPaginationController">
    <apex:form >
        <apex:pageBlock title="Pagination with SOQL Query" id="pgBlock">
            <apex:pageBlockTable value="{!Accounts}" var="acc" id="pgTable">
                <apex:column value="{!acc.Name}"/>
                <apex:column value="{!acc.Industry}"/>
                <apex:column value="{!acc.BillingState}"/>
                <apex:column value=…

Simple Pagination using Salesforce Standard list Controller in Visualforce page

Image
Pagination in Visualforce page without using Custom controller Salesforce has some limits when you want to show more then 1000 records in visualforce page. If we try to display more then 1000 records in visualforce page without implementing the pagination you will get "Collection size 1,250 (record count)  exceeds maximum size of 1,0000" Visualforce error.  Here I'm going to show you Simple way to implementing the pagination using salesforce standard controllers.  Visualforce page code for Pagination: <apex:page standardController="Lead" recordSetVar="Leads" >
   <apex:form >
       <apex:pageBlock title="Pagination with Standard List controller" tabStyle="lead" >
           <apex:pageblockTable value="{!Leads}" var="le" id="contactTable">
               <apex:column value="{!le.firstName}"/>
               <apex:column value="{!le.lastName}"/>
 …

How to use Map Methods in Salesforce Apex Classes

Image
Most Powerfull Apex Map Methods Map is the one of the best collection type in apex programming language. It's more powerfull and more flexible collection in apex. It stores data in the form of Key and Value. The Key and value in a map can be user-defined data types. Keys can only be Primitive data type, and Values can be primitive, sobject, apex class and any other collection type.(i.e list or set). Keys can't be Duplicates, values can.  Apex Map Methods: Now i'm going to show you some common map methods used in apex language. below is the basic syntax of the map. Map <key, value> mapname = new Map<key, value>();
Map <Key_Datatype, Value_Datatype> simpleMap = new Map <Key_Datatype, Value_Datatype> (); Define Simple Map: Defining a simple map of Key is Integer and Value is String. Map <Integer, String> simpleMap = new Map <Integer, String> (); Simple Add Elements to Map: Now I'm going to define a simple map then add elements to the m…

Dynamic Apex Useful Methods and check CRUD, FLS Permissions

Image
Useful Schema Describe Methods & check CRUD, FLS Dynamic apex enables developer to develop more flexible applications using describe information about the sobjects, their fields and child relationship information. Now here I'm going to show some useful methods used with Schema.DescribeSobject.
IsCustom() :  some time we need to check the object is Custom object or Standard object. It's difficult to find out. Now it's simple with IsCustom() method, we need to pass object name and it will return boolean true or false. See following sample code.  List<String> allCustomObjsList = new List<string>();
List<String> allStandardObjsList = new List<string>();
for(Schema.SobjectType obj : Schema.getGlobalDescribe().values())
     {
         Schema.DescribeSobjectResult objResult = obj.getDescribe();
            if(objResult.isCustom())
            {
                String strObjName =objResult.getname();
                allCustomObjsList.add(strObjName);