Scolldown Pagination in Visualforce Page

First of all, most important thing to know what is pagination?

Why we use it???

Most of the developers know about this but if you are beginner or do not know about pagination here is the explanation.

Pagination is used to display or handle the large number of sobject records and breaking the large number of records into the separate pages for viewing with in the salesforce so that you can improve the visualforce page or lightning component load times.

Pagination can be done using multiple ways.

  1. Pagination with a Standard Set Controller
  2. Pagination with a SOQL OFFSET in Apex

If you are dealing with limited records like upto 2,000 then you can use SOQL Offset in custom controller and display in visualforce using next and previous buttons or scrollbar.

But if you have requirement for more than 2,000 records then you can use Standard Set Controller and paginate records upto 10,000.

You can set any number of sobject records like 20,25 or any other number per page with the help of pagination.

In the article I am going to explain pagination using SOQL Offset in custom apex controller and display records in visualforce with the help of visualforce remoting and jquery.

This will also help you to understand some basic concepts of visualforce remoting and jquery.

So we have talked too much now It’s time for some code.

codeboogie

As you can see 15 Account (sobject) records per page is displaying using SOQL Offset.

Some pointers related to above visualforce page and apex controller which  would be helpful to understand.

  1. getAccountsData() is the javascript function which is calling initially on load of page for getting first 15 records or when user reaches the end of page for getting the further 15 records from server side.
  2. scrollTop() is the javascript property which returns the number of pixels an element content is scrolled vertically.
  3. innerHeight() is the javascript property which returns the height of window’s content area.
  4. scrollHeight() is javascript property which returns the entire height of element including padding.

Refer Below Links for some more details of Pagination.

http://www.sfdcpoint.com/salesforce/pagination-using-standard-set-controller-salesforce/

https://developer.salesforce.com/page/Paginating_Data_for_Force.com_Applications

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_pagination.htm?search_text=pagination

Hope you find this helpful, in case of any queries/concerns, please post a reply or drop an email to me at sfdcsagarsindhi@gmail.com .

Create Remote Site Setting through Visualforce Page

Hey Salesforce Ohana, I am back with new blog post. In this blog I will explain How to create a Remote Site Setting through coding.

Most of developer or admin usually create Remote Site Setting through Remote Sites Section [Administer -> Security Control -> Remote Site Settings] in your Salesforce organization.

If you do not know what is Remote Site Setting?

Why we use Remote site setting?

You can refer this blog post for complete details.

Now it’s time for coding.

Coding

Before starting , you should know about MetaData API .

A Secrete key to access, create your salesforce.com Metadata like Workflows, Remote Site, Validation Rules.

Let’s download MetaData WSDL File [Build -> API -> MetaData WSDL] and generate apex class using this WSDL File [Build -> Develop -> Apex Classes -> Generate from WSDL] or you can refer this MetadataService apex class.

1st

Add your Salesforce Organization domain name and your visualforce page domain name in Remote site setting by following steps.

[Administer -> Security Control -> Remote Site Settings]

Now, Create a Visualforce Page for input Remote site details and apex controller for business logic.

Below is your apex controller code which will call MetaDataPort Method in the MetaDataService apex class for generating of session Id your salesforce organization and enter remote site details and call createMetaData() method.

2nd

You can refer the complete code here.

Hope you find this helpful, in case of any queries/concerns, please post a reply or drop an email to me at sfdcsagarsindhi@gmail.com .

Happy Coding 🙂

 

 

 

Salesforce DX – Salesforce Developer Experience

Salesforce Developer Experience which is the most Trending Topic in these days.

SFDX is a new tool to manage and develop apps on the force.com platform. It is created for developers to build apps on force.com together in a team.

It makes the developers experience easy so that developers can do coding with less effort in a short period of time and build apps together with version control system.

It also changed the way to deploy the application on force.com platform.

Some Import features of Salesforce DX

  • Scratch Org
  • Source Sync
  • Salesforce Command Line Interface(CLI)
  • Test Runner
  • Continuous Integration
  • Force IDE and Visual Studio with DX Support

Let’s start some work on SFDX tool

Download SFDX CLI and install in your System.

Enable DEV HUB in your org so you can create scratch orgs from CLI and use this tool easily or you can create a 30 days trail org in which DEV HUB is by default activated.

Open your Command window and authorize your org

sfdx force:auth:web:login

it will redirect to salesforce login page automatically and then enter your DEV HUB org username and password.

After login you will get something like this.

1st

Check your connected orgs.

sfdx force:org:list

2nd

I have worked on these three org that’s why it’s showing these three orgs list but you will get only one org DevHub if you are using it first time.

You can check the all available things which you can do using SFDX CLI and commands list with explanation by using below two commands

Sfdx force –help

Sfdx force:doc:commands:list

This slideshow requires JavaScript.

Let’s create a SFDX Project

sfdx force:project:create -n ProjectName

5th

Your Project contains these files and folders.

6th

sfdx-project.json is the project configuration file contains the sfdx project information and it also tell the sfdx where to put all components when you pull data from scratch org.

7th

project-scratch-def.json is the scratch org definition file indicates which type of scratch org will be created and some basic details for scratch org like orgName or edition of Scratch org.

You can manually edit this file like replace Developer edition to Enterprise if you want to create Enterprise Edition scratch org or any other edition.

8th

Force-app folder contains all components like apex class, custom objects, visualforce pages etc..

Create a Scratch Org

sfdx force:org:create -s -f config/project-scratch-def.json -a AliasName

-s indicates this scratch org would be the default scratch org for this project.

-f indicates the path of scratch org definition file

-a indicates the alias name for this scratch org

Alias Name will be helpful when you have multiple scratch orgs. You just need to put alias name for open scratch org instead of using the username of scratch org.

9th

Open Scratch org

sfdx force:org:open

This will open the default scratch org if you have otherwise you can use alias name to open other scratch org.

sfdx force:org:open –u AliasName

10th

Create a Apex class in your project

sfdx force:apex:class:create -n ApexclassName -d force-app/main/default/classes

-n indicates the Apex class Name

-d indicates the Path for Apex class in your project

11th

Open Apex class in your project and do some thing and push all changes to scratch org

12th

Push all changes to Scratch org

sfdx force:source:push

13th

Let’s review it in the scratch org

Login in to the scratch org by sfdx force:org:open using SFDX it will automatically open your scratch org or you can get list of orgs to know the details of all connected orgs and scratch orgs.

14th

Let’s do some change in the apex class from Scratch org and pull changes you your project.

This Is the way you can sync all changes with your project to scratch orgs.

sfdx force:source:pull

16th

15th

17th

You can refer some related blog posts or official site for more details-

https://audit9.blog/2017/08/06/salesforce-dx/

http://bobbuzzard.blogspot.in/2017/12/sfdx-and-metadata-api.html

https://www.salesforce.com/products/platform/products/salesforce-dx/

http://www.jitendrazaa.com/blog/tag/sfdx/

Hope you find this helpful, in case of any queries/concerns, please post a reply or drop an email to me at sfdcsagarsindhi@gmail.com .

 

 

How to Tackle View State Issue During Upload file as a Attachment through Visualforce Page – Part 2

1st

Hello guys , I am Back with my new Blog Post . In this Post You will Learn Two things .

  • Upload file as a Attachment  Without Apex Controller
  • What is Salesforce Ajax toolkit and How you can use Ajax Toolkit for Upload File

Please Refer my Previous Blog Posts to get to know Upload file through visualforce and Tackle View State Issue through apex Controller

First of all Do you Know about Salesforce Ajax Toolkit ???q-590x446

If you don’t know then do not worry just take long breath and read this artical.

Let’s come to the Point and discuss What is Salesforce Ajax Toolkit ?????

Ajax Toolkit is like a Javascript Wrapper which you can use in Your Visualforce Page to Interact with Salesforce Standard and custom Objects .

You can query Salesforce Objects Data , Create records and attachments without using Apex with your Visualforce Page.

Now the Questions arise When to use ajax toolkit??

Best situation to work with ajax toolkit is when you have to work with small amount of data.

AJAX works best with  small amounts of data (up to 200 records, approximately six fields with 50 characters of data each).

You have to follow three steps for working with ajax toolkit in your visualforce Page.

  • Connecting to the API – Include Connection.js file that is ajax toolkit Javascript file in your Visualforce Page and Get the Sforce Session using sforce.connection.sessionId='{!GETSESSIONID()}’

    After execution of Connection.js script , the toolkit is loaded and a global object, sforce.connection, is created. This object contains all of the API calls and AJAX Toolkit methods, and manages the session ID.

  • Embed API Calls in Javascript – Write Javascript code for Making Instance of  Sforce Object like “new sforce.SObject(“Attachment”)” and create attachment using sforce.connection.create([attachment] .
  • Processing result – Process the Result on creation of attachment and show success or failure message .onSuccess : function(result, source) {

    if(result[0].getBoolean(“success”)) {

    // do your code whatever you want to show on success

    }

    },

    onFailure : function(error, source) {

    // do your code on failure

    }

You can go through the Salesforce Ajax Toolkit Developer Docs for more reference .

Here is the Look of your Visualforce page .

When you Load the Page .

1st

When you Clicked Upload Button Without Record ID in URL .

3rd

When you Clicked Upload Button Without Selecting File for upload.

4th

When you selected file and clicked Upload Button .

2nd

Here is the Visualforce Page Code With Ajax Toolkit.

Hope you find this helpful, in case of any queries/concerns, please post a reply or drop an email to me at sfdcsagarsindhi@gmail.com .