Skip to main content
I have two custom objects [access.log & trans.log] who receive daily updates [New Records] from an external system. After 31 days we don't need them anymore and we would like to delete them. Both objects have a date field on the record 'Log_date__c'.

I know that you can make a job that deletes these records on a daily basis.

My question;

- How do I write a code that deletes the right records? (Log_date__c older than 31 days)

- How/where do I put in SFDC? (Apex Class or Trigger! - Both!)

Are there any who can help me progress. In which case it will be my first code in SFDC.
18 respostas
  1. 8 de jun. de 2015, 12:42
    Hi Allan,

    These steps might be help full for you.

    Create a schedulable apex class 

    global class DeleteRecords implements Schedulable{

    global void execute(SchedulableContext SC) {

    List<Custom_Object__c> customObj = [select Id FROM Custom_Object__c WHERE createddate = LAST_N_DAYS:30];

    if(!customObj.isEmpty())

    delete customObj;

    }

    }

     Now go to Setup -> Develop -> Apex classes . Click on Schedule Apex Button and schedule your apex like this 

    Hi Allan,These steps might be help full for you.

    Select your preffered time (Time will be based on the users time zone) and Save.

    Your job will run per month. You can check the status of your job by Setup -> Jobs -> Apex Jobs.

    Thanks.