• vishnushivaraman
  • NEWBIE
  • 30 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi Everyone,

I created a Visualforce page with a Delete All button. On click of the button, it will call the controller method and the controller method executes a batch class that will delete all the records from the object. 
Everything working as expected but if we click browser refresh button or F5 key while the deletion is in-progress then the batch class is re-initiating. 
How to stop the browser refresh.

My code as follows :

Viusalforce page :
<apex:page standardController = "Account" extensions="DeleteRecordsExtn">
    <apex:commandbutton label="DeleteAll" action="{!doDelete}"/>
</apex:page>

Controller method :
public void doDelete() {
    DeleteRecordsBatch delBatch = new DeleteRecordsBatch();
    Database.executeBatch(delBatch);
}

Batch class :
public class DeleteRecordsBatch implements Database.Batchable<sobject>{

public Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator('SELECT Id FROM Account');
}
public void execute(Database.BatchableContext BC, List<SObject> lstRecords){
    Database.delete(lstRecords, false);
}
public void finish(Database.BatchableContext BC){
}

Can anyone please help me in this scenario.
Hi Everyone,

I created a Visualforce page with a Delete All button. On click of the button, it will call the controller method and the controller method executes a batch class that will delete all the records from the object. 
Everything working as expected but if we click browser refresh button or F5 key while the deletion is in-progress then the batch class is re-initiating. 
How to stop the browser refresh.

My code as follows :

Viusalforce page :
<apex:page standardController = "Account" extensions="DeleteRecordsExtn">
    <apex:commandbutton label="DeleteAll" action="{!doDelete}"/>
</apex:page>

Controller method :
public void doDelete() {
    DeleteRecordsBatch delBatch = new DeleteRecordsBatch();
    Database.executeBatch(delBatch);
}

Batch class :
public class DeleteRecordsBatch implements Database.Batchable<sobject>{

public Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator('SELECT Id FROM Account');
}
public void execute(Database.BatchableContext BC, List<SObject> lstRecords){
    Database.delete(lstRecords, false);
}
public void finish(Database.BatchableContext BC){
}

Can anyone please help me in this scenario.
Hi, 

  In below code I am hard coding RW: and FW: in the loop to compare and replace please suggest me how to  user keywords. 
public static void processUpdate(list<Case> cseLst) {
        String FWSubject;
        String RWSubject;
        String CaseSubject;
        list<Case> caseLst = new list<Case>();
       
        for (Case c : cseLst) {       
            if(c.subject <> null){     
                // Remove FW and RW from case subject to get exact string
                if(c.subject.Contains('FW:')){
                    FWSubject = c.subject.replaceAll('FW:','');
                    System.debug('FQ Trim String :' + FWSubject);
                    CaseSubject = FWSubject;     
                } else if(c.subject.Contains('RW:')){ 
                    RWSubject = c.subject.replaceAll('RW:','');
                    System.debug('RW Trim String :' + RWSubject);   
                    CaseSubject = RWSubject;

   }
}

Thanks
GMASJ
  • February 28, 2019
  • Like
  • 2