You need to sign in to do that
Don't have an account?
batch apex / i just want it to "update" all opportunities once a week
I have apex code that populates fields, and I want to run the "before update" on all opportunities once a week to make sure that these fields that are populated are current.
I've created the scheduled batch apex in classes and have set it to schedule and run, and it's running but it isn't running the "before update" on all of my opportunities.
here's my scheduler:
global class batchitupson_schedule implements Schedulable { global void execute(SchedulableContext scMain) { BatchUpdateForecast clsBatchItUpSon = new BatchUpdateForecast('Select Id, Name FROM Opportunity','Opportunity','Source_Name__c','Gwins'); ID idBatch = Database.executeBatch(clsBatchItUpSon, 100); } }
and here is my Scheduled class that is batchable, as you can tell, all i want it to do is open all the opportunities and update them, much like if you were to click through them manually and click "Edit" then click "Save" which then runs my "before update" code for the opportunity
global class BatchUpdateForecast implements Database.Batchable<sObject>{ global final String Query; global final String Entity; global final String Field; global final String Value; global BatchUpdateForecast (String q, String e, String f, String v){ Query=q; Entity=e; Field=f;Value=v; } global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<sObject> scope){ //for(sobject s : scope){ //s.put(Field,Value); //} update scope; } global void finish(Database.BatchableContext BC){ } }
Hi,
I'm a little bit fuzzy on exactly what you're trying to accomplish.
Do you also have a trigger on your opportunity object? I'm assuming this is what you mean by "before update". And it looks like you're trying to save your object records so the trigger will run, correct?
Can you post the trigger?
Gabriel Alack
Contact Us - We Can Help!
Salesforce Superheroes
------------------------------
help@salesforcesuperheroes.com
www.salesforcesuperheroes.com
1-888-407-9578 x122
yes, i have a trigger:
yeah the idea is to get this trigger to run nightly, and i thought that the best way to do this was to batch through the opportunity's using a scheduled batch class and update all of them.