• Shweta Tiwari 7
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi I have a requirement where I have to update a field in Custom Object when I click on a Custom Button(it's an HTML Component) in my Visualforce Email Template. I have added a Component and Controller in the Email Template but I am not able to track the action as form tag is Command Button is not supported. Can anyone faced this issue earlier.

Please help!!
My requirement was to look for all the records deleted by a particular user spanning mulitple objects and delete those records from recycle bin. I tried to come up with this code and it worked, but when there is too much of data it hits Apex governor limit. I am new to coding and don't know how to circumvent that. I initially tried writing my query in start method but I was not able to query multiple objects there using for loop.

I am using custom setting (EmptyRecycleBinBatch) to hold object API names.. Any suggestion is appreciated!

global class EmptyRecycleBinBatch implements Database.Batchable<sObject>, Schedulable {

    global Database.QueryLocator start(Database.BatchableContext BC) {
        String Query='Select Id, ObjectAPIName__c From EmptyRecycleBinBatch__c';
         return database.getquerylocator(Query);
   }

    global void execute(Database.BatchableContext BC,List<EmptyRecycleBinBatch__c> sObjRecords) {
        System.debug('in execute method');
        User userid= [Select Id, Name from User where User.Name= ' test user' And isActive= true Limit 1];
        String Query;
        
        for(EmptyRecycleBinBatch__c sOb: sObjRecords){ 
        
        SYstem.debug('object name :'+sOb.ObjectAPIName__c); 
          Query = 'SELECT ID from '+sOb.ObjectAPIName__c+' where isDeleted = true AND CreatedById = \''+userid.Id+'\' all rows';
        system.debug('query '+Query );            
        List<Sobject> sObjtocreate = new List<Sobject>();    
        sObjtocreate = Database.query(Query);
            System.debug('list of items to delete'+sObjtocreate);
      if(sObjtocreate != null && !sObjtocreate.isEmpty()) { 
          
     try{
         //system.debug(' deleting :'+sObjtocreate);
           Database.emptyRecycleBin(sObjtocreate); 
            if(test.isRunningTest())
            {
                 throw new applicationException('Exception');
            }
        }
        catch(Exception e){
            System.debug('ERROR on Delete:' + e);
        }
       }
      }
     }     
    public class applicationException extends Exception 
    {
    
    } 
    global void finish(Database.BatchableContext BC) {
        
    }
    global void execute(SchedulableContext sc) {
        database.executebatch(new EmptyRecycleBinBatch());
    }
}
Hi I have a requirement where I have to update a field in Custom Object when I click on a Custom Button(it's an HTML Component) in my Visualforce Email Template. I have added a Component and Controller in the Email Template but I am not able to track the action as form tag is Command Button is not supported. Can anyone faced this issue earlier.

Please help!!