Skip to main content
I've created an apex class to update all accounts where a certain field contains a date that is more than 12 months ago, I can't seem to get it working? Any ideas?  If they meet the criteria it updates two fields.

 

I've got a class:

 

public class firstInvoicedDate {

 

 public static void updateFirstInvoicedDates() {

 

      // Find all accounts where first invoice date is more than 12 months ago and revenue type is new business

 

      Account[] firstinvoiceAccounts = [SELECT Id, First_Invoiced_Date__c, Revenue_Stream__c, Revenue_Type__c  FROM Account WHERE First_Invoiced_Date__c < LAST_N_DAYS:365 AND Revenue_Type__c = 'New Business'];

 

      // loop through them and update the Description field

 

      for (Account acct : firstinvoiceAccounts) {

 

          acct.Revenue_Stream__c = 'Retention'; acct.Revenue_Type__c = 'Retention';

 

      }

 

      // save the change you made

 

      update firstinvoiceAccounts;

 

    }

 

}

 

And a schedule class:

 

global class runFirstInvoiceDate implements Schedulable {

 

   global void execute(SchedulableContext sc) {

 

      firstInvoicedDate b = new firstInvoicedDate(); 

 

   }

 

}

 

Not sure where I am going wrong?

 

 
6 answers
  1. Jul 16, 2019, 11:32 AM

    Hi,

    I’ve updated the schedule class and re run the process but the test records falling within the criteria still didn’t update.

    Thanks

    Chris

    Chris Porter

    Commercial Lead - DBS & Safeguarding

    Personnel Checks

    chris.porter@personnelchecks.co.ukwww.personnelchecks.co.uk

    Tel: 01254 355677

    Mob: 07532 744621

    powered by

    Personnel Checks is a top 30 Registered Umbrella Body for the Disclosure and Barring Service (England and Wales), providing a fast, professional and online DBS service to all types of organisations throughout the UK. We assist, inform and give direction, helping clients make the best recruiting and safeguarding choices.

    This e-mail and its contents are only intended for the addressee(s) named. It may be or may include privileged and confidential information. If you are not an intended addressee you must not copy or distribute it, disseminate it or use the information contained in it or take any action in reliance on it. If it has been sent to you in error or if you have received it in error please notify us immediately and delete it from your system. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Personnel Checks Ltd. Although this e-mail and any attachments are believed to be free of any virus or other defects which might affect any computer or IT system into which they are received, no responsibility is accepted by Personnel Checks Ltd or any of its directors, staff or associated businesses or contacts for any loss or damage arising in any way from the receipt or use thereof.

    Personnel Checks is the trading name of Personnel Checks Limited, registered office; One Cathedral Square, Cathedral Quarter, Blackburn, BB1 1FB. Registered in England, number 08101751

0/9000