function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Naga Balji BNaga Balji B 

Can any one help me ...can we create visualforce pages for shedule and batch apex? Give me some examples?

Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same
1) http://www.infallibletechie.com/2015/10/how-to-show-status-of-batch-job-in.html
2) http://salesforce.stackexchange.com/questions/99020/why-does-my-actionpoller-wait-for-my-batch-process-to-be-done-before-it-polls

Sample Batch:

global class AccountUpdate Implements Database.Batchable <sObject> {
    global Database.queryLocator start(Database.BatchableContext bc) {
        String SOQL = 'SELECT Id, Description FROM Account';
        return Database.getQueryLocator(SOQL);
    }

    global void execute(Database.BatchableContext bc, List<Account> listAccount) {
        for(Account a : listAccount) {
            a.Description = 'Updated on ' + system.today();
        }
        update listAccount;
    }

    global void finish(Database.BatchableContext bc) {
    }
}

Visualforce Page:

<apex:page controller="Sample">
<apex:form >
    <apex:pageBlock id="pg">
        <apex:pageBlockSection rendered="{!batchStatusBool}">
            <apex:actionStatus id="act" startText="Checking..." />
            Batch Account Status is {!batchStatus}
            <apex:actionPoller interval="5" action="{!checkBatchStatus}" enabled="{!pollerBool}" reRender="pg" status="act"/>
        </apex:pageBlockSection>
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Call Account Update Batch" action="{!callAcctUpdateBatch}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>
</apex:page>

Apex Class:

public class Sample {
    public Boolean batchStatusBool {get;set;}
    public String batchStatus {get;set;}
    Id batchId;
    public Boolean pollerBool {get;set;}

    public Sample() {
        batchStatusBool = false;
        pollerBool = false;
    }
   
    public void callAcctUpdateBatch() {
        batchStatusBool = true;
        AccountUpdate obj = new AccountUpdate();
        batchId = Database.executeBatch(obj, 2);
        checkBatchStatus();
    }
   
    public void checkBatchStatus() {
        AsyncApexJob job = [SELECT Id, Status FROM AsyncApexJob WHERE Id =: batchId];
        batchStatus = job.Status;
        if(batchStatus == 'Completed') {
            pollerBool = false;
        } else {
            pollerBool = true;
        }
    }
}

Let us know if this will help you