How to give SOQL limit size dynamically for retrieving records using Apex in Salesforce?

Sample Code:

Visualforce page:

<apex:page controller="Sample">
<apex:form >
    <apex:pageblock >
        <apex:pageBlockTable value="{!MemList}" var="M">
            <apex:column value="{!M.Name}"/>

Apex Controller:

public class Sample {  
    Integer n = 5;
    public List<Member__c> MemList {get;set;}
    public Sample() {
    /* We can write like this too
        MemList = [SELECT Name FROM Member__c LIMIT : n];
        String Soql = 'SELECT Name FROM Member__c LIMIT ' + n;
        MemList = Database.query(Soql);


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit