+ Start a Discussion
Adam BinderAdam Binder 

Help needed building Apeex code to update all records

Help!

I have no experience with Apex classes and need help building one...

I have a custom object called Orders_and_Invoices__c
I have processes built in the process builder that need to be ran daily, so I need something to kick off the updates (as you can't schedule these).
There are around 30k worth of records so a time based work flow is no good. From my googling it looks like I need and Scheduled Apex Class to update all records in this object which in turn will run my processes.

Can someone help me build the code to do this?
buggs sfdcbuggs sfdc
Adam,

Here is sample code,which will help you,and let me know if you have strucked?
 
global class DailyLeadProcessor implements Schedulable {

    global void execute(SchedulableContext ctx) {
        List<Lead> lList = [Select Id, LeadSource from Lead where LeadSource = null];
        
        if(!lList.isEmpty()) {
			for(Lead l: lList) {
				l.LeadSource = 'Dreamforce';
			}
			update lList;
		}
    }
}


Once you finish the class, you can go to Setup -> App Setup  ->Develop -> Apex Classes and click on the "Schedule Apex" button and set up this class to run on the days/times you'd like. 

Hope this helps and welcome to Apex!
https://developer.salesforce.com/forums/?id=906F0000000BancIAC (https://developer.salesforce.com/forums/?id=906F00000005GBJIA2)

https://developer.salesforce.com/forums/?id=906F00000005GBJIA2