• Vijay Kumar Rebbala 1
  • NEWBIE
  • 45 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 7
    Replies
//VFP:
<apex:page controller="Accountlistctrl">
    <apex:dataTable value="{!acctlist}" var="accs" columns="7" rows="{!rowcount}">
        <apex:outputField value="{!accs.Id}"/>
    </apex:dataTable>
</apex:page>

//CTRL:

public class Accountlistctrl {

public list<Account> acctlist {get;set;}
public Integer rowcount {get;set;}

    public Accountlistctrl(){
        acctlist = [SELECT Id, Name FROM Account Limit 19];
        integer s = acctlist.size();
        system.debug('***********list size*************'+s);
        rowcount = Integer.valueOf(Math.ceil(s/7));
        system.debug('***********rowcount*************'+rowcount);
    }
}
Hi,
Since we cannot create an email notification of data used in salesforce. I'm trying to write a scheduled code to take a snapshot and send an email.
Did anyone have a reference to lessen my work.

Thanks,
Vijay
Class:
global class DeleteoldCases{
    Public void SFDCDeleteoldCases(){
        List<Case> QueryCases = [SELECT Id FROM Case WHERE CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
        Integer QueryCount = database.countQuery('SELECT Count() FROM Case WHERE CreatedDate < LAST_N_MONTHS:18  LIMIT 9000');
            If (QueryCases.isEmpty())
            {
                return;
            }
            try{
                delete QueryCases;
            }catch(DmlException e) {
                System.debug('An unexpected error has occurred: ' + e.getMessage());  
            }catch(NullPointerException npe) {
                System.debug('The following exception has occurred: ' + npe.getMessage());         
            }finally{
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();         
            String[] toAddresses = new String[] {'CSAdmins@zynga.com'};        
            mail.setToAddresses(toAddresses);         
            mail.setSubject('Salesforce ZRM CaseDelete Status');         
            mail.setPlainTextBody('The Scheduled Apex job processed ' +QueryCount);         
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
    }
}

Test Class:

@isTest
public Class testDeleteoldCases {
    public static testMethod void testschedule() {  
        DeleteoldCases delca = new DeleteoldCases();
        delca.SFDCDeleteoldCases();
        
        Case newcase = new Case();
        newcase.Subject = 'Testing123456798';
        insert newcase;
List<Case> QueryCases = [SELECT Id FROM Case WHERE Subject = 'Testing123456798' ORDER BY CreatedDate ASC  LIMIT 9000];
        try {
            if(Test.isRunningTest()) {  
                QueryCases = null;
            }
            delete QueryCases;
        } catch(Exception e) {           
            system.debug('Failed to delete cases');
        }
    }
}
The code which i wrote executes but doesn't work. Can you explain why??
Scheduled Class:
global class Scheduler_DeleteoldCases implements Schedulable{
  global void execute(SchedulableContext SC) {
     DeleteoldCases gm = new  DeleteoldCases() ;
  }}

Apex Class:
global class DeleteoldCases{
    Public void DeleteoldCases(){
        Case[] QueryCases = [SELECT Id FROM Case WHERE CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
            system.debug('********List of Cases********'+QueryCases);
            If (QueryCases == null || (QueryCases!=null && !QueryCases.isEmpty()))
            {
                return;
            }
            try{
                delete QueryCases;
            }catch(DmlException e) {
                System.debug('An unexpected error has occurred: ' + e.getMessage());       
        }
    }
}
 
I need to help on how to execute the schedule class from Developer console and also please review the code for any mistakes.

//Scheduler Class
global class Scheduler_DeleteoldCases implements Schedulable{
  global void execute(SchedulableContext SC) {
     DeleteoldCases gm = new  DeleteoldCases() ; 
  }}


global class DeleteoldCases{
    Public void DeleteoldCases(){
        List<Case> QueryCases = [SELECT Id FROM Case WHERE Case.CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
        If (QueryCases == null){return; }
        system.debug('********List of Cases********'+QueryCases);
        try{
            delete QueryCases;
        }catch(DmlException e) {
            System.debug('An unexpected error has occurred: ' + e.getMessage());
        }  }}




How to escape the exception if there are no results from Soql Query and do I hit any Governer Limits by looking at the code??

global class DeleteoldCases{
    Public void DeleteoldCases(){
        List<Case> QueryCases = [SELECT Id FROM Case WHERE Case.CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
        If (QueryCases == null){return;}
        system.debug('********List of Cases********'+QueryCases);
        try{
            delete QueryCases;
        }catch(DmlException e) {
            System.debug('An unexpected error has occurred: ' + e.getMessage());
        }  
    }
}
global class DeleteoldCases{
    List<Case> QueryCases = [SELECT Id FROM Case WHERE Case.CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
    try{
    delete QueryCases;
    }catch(DmlException e) {
    System.debug('An unexpected error has occurred: ' + e.getMessage());
    }  
}
Hi All.
I have a scenario, where i need to create a Public Group through an Apex Class.
I need help.
Hi,
Since we cannot create an email notification of data used in salesforce. I'm trying to write a scheduled code to take a snapshot and send an email.
Did anyone have a reference to lessen my work.

Thanks,
Vijay
The code which i wrote executes but doesn't work. Can you explain why??
Scheduled Class:
global class Scheduler_DeleteoldCases implements Schedulable{
  global void execute(SchedulableContext SC) {
     DeleteoldCases gm = new  DeleteoldCases() ;
  }}

Apex Class:
global class DeleteoldCases{
    Public void DeleteoldCases(){
        Case[] QueryCases = [SELECT Id FROM Case WHERE CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
            system.debug('********List of Cases********'+QueryCases);
            If (QueryCases == null || (QueryCases!=null && !QueryCases.isEmpty()))
            {
                return;
            }
            try{
                delete QueryCases;
            }catch(DmlException e) {
                System.debug('An unexpected error has occurred: ' + e.getMessage());       
        }
    }
}
 
I need to help on how to execute the schedule class from Developer console and also please review the code for any mistakes.

//Scheduler Class
global class Scheduler_DeleteoldCases implements Schedulable{
  global void execute(SchedulableContext SC) {
     DeleteoldCases gm = new  DeleteoldCases() ; 
  }}


global class DeleteoldCases{
    Public void DeleteoldCases(){
        List<Case> QueryCases = [SELECT Id FROM Case WHERE Case.CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
        If (QueryCases == null){return; }
        system.debug('********List of Cases********'+QueryCases);
        try{
            delete QueryCases;
        }catch(DmlException e) {
            System.debug('An unexpected error has occurred: ' + e.getMessage());
        }  }}




How to escape the exception if there are no results from Soql Query and do I hit any Governer Limits by looking at the code??

global class DeleteoldCases{
    Public void DeleteoldCases(){
        List<Case> QueryCases = [SELECT Id FROM Case WHERE Case.CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
        If (QueryCases == null){return;}
        system.debug('********List of Cases********'+QueryCases);
        try{
            delete QueryCases;
        }catch(DmlException e) {
            System.debug('An unexpected error has occurred: ' + e.getMessage());
        }  
    }
}
Hi All.
I have a scenario, where i need to create a Public Group through an Apex Class.
I need help.