Lightning component table using Lightning Datatable with sorting and pagination.

I recently worked on the project where I needed to create table with pagination, sorting and be able to select page size.

I tried to find a good working example online and could find example where it will work with unlimited number of pages. I saw examples that used LIMIT in the query, which mean not all the records will be shown in the table.

I decided to write a component that will work with any number of records and will use StandardSetController and it’s methods like next(), previous() etc.

LightningTable.cmp

LightningTableController.js

LightningTableHelper.js

LightningTableController.apxc

 public class LightningTableController {
    private static ApexPages.StandardSetController ssc;
    private static String query = 'SELECT Id, Name, FirstName, LastName, Email, MobilePhone FROM Contact';
    
    @AuraEnabled
    public static ResultWrapper getData( Integer pageSize, Integer pageNumber, String sortBy, String sortOrder ){
        
        if( sortby != NULL && sortOrder != NULL  ){
            query += ' ORDER BY '+ sortby+' '+ sortOrder+' NULLS LAST';
        }
       
        ssc = new ApexPages.StandardSetController( Database.getQueryLocator( query ) );
        //set page size
        ssc.setpagesize(pageSize);
        //set page number 
        ssc.setPageNumber( pageNumber );
        return new ResultWrapper( (List)ssc.getRecords(), ssc.getResultSize());
    } 
    
    public class ResultWrapper {
        
        @AuraEnabled
        public List result {get;set;}
        @AuraEnabled
        public Integer totalNumberOfRecords {get;set;}
        
        public ResultWrapper( List result, Integer totalNumberOfRecords) {
            this.result = result;
            this.totalNumberOfRecords = totalNumberOfRecords;
        }
    }
}

} 

		
					
			

How to fix error “Java runtime could not be located. Set one using the salesforcedx-vscode-apex.java.home VS Code setting” in Visual Studio code.

Today I was trying to set up Visual Studio Code on my personal computer and when I tried to create project I received this error: “Java runtime could not be located. Set one using the salesforcedx-vscode-apex.java.home VS Code setting”.

The message is self-explanatory, however it took me few minutes to figure out how to fix it.

What is causing issue?

Current version of Salesforce Extension Pack for Visual Studio Code requires Java Platform, Standard Edition Development Kit 8 (JDK8). If you don’t have it – install it first, you can find it and download it here.

I received this error even though I had JDK8 installed and configured in PATH environment variable to point to the right folder.

How to fix this error?

In Visual Studio Code go to File –> Preferences –> Settings or (Ctrl + comma)

Scroll down and find Salesforce Apex Configuration and on the right side add:

“salesforcedx-vscode-apex.java.home”: “path_to_JDK8”