Tech Talk: Whats New in Apex Code FAQ
What's New in Apex Code FAQ
This is the FAQ for the Tech Talk: What's New in Apex Code webinar.
Q: I want to create a managed package that can have 2 different configuration options. Can I create a custom setting that is editable by the end user so they can pick their config setting? Could I do this via a VF page that allows user to edit the custom setting data for the org?
A: Yes, this is the primary use case for custom settings
Q: Custom settings can be packaged. Can I package the "managed" part, the data value?
A: Not yet. That is being worked on, though.
Q: Why doesn't the system allow updating a custom setting after updating a custom object?
A: This is a bug, which is fixed in the next release
Q: AsyncApexJob seems to only return the number of batch jobs as opposed to the number of items being processed by the batch.
A: The AsyncApexJob object seems to have a "JobItemsProcessed" which is the number of job items processed.
Q: But if I move off the page, and therefore the controller, I've since lost the job id
A: Then you'll either need to save it in the DB, or save it in a queryString param between pages.
Q: If you move off the batch request visualforce page, how would you get the status without running reports or going into setup?
A: Query the AsyncApexJob object. Database.executeBatch(new BatchJob()); returns the AsynApexJob id as a String for you to query.
Q: Do these processes apply against limits on total number of async requests per day?
A: No
Q: What about exception handling on a scheduler process?
A: Apex users can implement their own email notification so they can be notified when a scheduled job executes and fails.
Q: Does scheduler run in asynchronous framework?
A: Yes.
Q: When these features will be available?
A: Batch and Custom Settings are currently available, Apex Scheduler is currently scheduled for the next release.
Q: Any plans to increase the granularity of scheduling, say, for example, once every 5 minutes, etc.?
A: You can schedule a job to run every 5 minutes via the API.
Q: Can you schedule quarterly or annually?
A: Yes, but it won't be as easy as saying "quarterly". You'd have to work out the cron expression.
Q: Which org is allowed to have Apex Scheduler enabled ?
A: It's currently in pilot, and I believe it's open to any org that can use Apex (ie: DE, EE, UE)
Q: Is there a way of handling the end of a future call with a finish() method like in Batch Apex??
A: There's no built in way, you'd have to create your own.
Q: What are the benefits, if any, of making batch size > 1 in a Batch Apex job?
A: Your batch job will complete faster because there is less queue movement required in the background.
Q: Are there any time limits for the execution of each batch or for an entire Batch Apex job?
A: I believe there's a 10 second of CPU time limit per iteration of execute(). CPU time does not include db queries or callouts
Q: Can Batch Apex execute base on schedule time?
A: Yes, through Apex Scheduler.
Q: Can you update Apex Schedule programmatically?
A: No. You have to unschedule the job and schedule a new one. Also note that scheduled classes can not be edited until the scheduled job completes.
Q: Does Apex schedule require user to log in to run?
A: No - you can trigger in say with a button on a Visualforce page, or a trigger or a web service. Anything that runs code that starts the scheduling.
Q: In the executeBatch method can I include queries on other objects much as I can in a trigger?
A: Yes
Q: Is there a way to do mass updates to records in batchmode without effecting the lastmoddate?
A: No
Q: Will we be able to select a single test to be executed, as opposed to always running all tests?
A: You can select a single test class to be executed, but there are no plans to make a way to execute a single test method.
Q: Are call outs allowed in a batch Apex
A: Yes. One callout per iteration of execute I believe.
Q: Can values or data in custom settings be modified in customer org, if custom settings are deployed using a managed package by developer?
A: No
Q: Will we be able to maintain a queue such that if we use Batch Apex in triggers .. can we queue Batches so that no more than 5 jobs execute in parallel?
A: You will be able to check the status of your queue by querying the AsyncApexJob object for any jobs in the ENQUEUED, or RUNNING status.
Q: Can I set Custom Setting values or can I just read them?
A: Public custom settings are settable by anyone, Protected custom settings are settable only by code in the same namespace
Q: I can see that we can deploy custom settings using Change Sets. Can we also deploy them from Eclipse or packages?
A: Yes, Custom Settings are available in the Metadata API, and thus from Eclipse and packaging.
Q: Do you HAVE to specify an end date? What if you want a scheduled job to run indefinitely?
A: You can specify the job to run indefinitely using the API.
Q: Custom settings have a 10MB limit for the entire org. do you get a hard error if you exceed that or is it a last in, first out approach?
A: You will receive a hard error I believe.
Q: PE doesn't have Apex, but an AppExchange package can be flagged to run Apex in a PE org. does this permission bring with it Batch Apex and the Scheduler, so that the app can perform these things in a Professional Edition org?
A: Yes
Q: Will we be able to have time based trigger to kick off code? for example at 4pm we will be able to kick something off?
A: Yes - that is Apex Scheduler.
Q: Can you combine Apex Scheduler with Batch Apex?
A: Yes
Q: How is record locking affected with dealing with the large batch processes?
A: The records are locked during the execution of a queryLocator (such as in the start method) after that method has been executed, all the records are then unlocked. If you want to lock the records during execute, you have to re-query for the objects and use the "FOR UPDATE" keyword in your query.
Q: During Salesforce maintenance, will the scheduled jobs run according to time scheduled?
A: Scheduled jobs will resume as soon as maintenance is complete.
Q: About record locking.. if a user has a record locked for update. does the process A: Return to update the record when it is unlocked?
No, but if a record is locked, it will retry for either 5 or 10 seconds (I can't remember off the top of my head) before failing with a "Resource Unavailable" error.
Q: How can I configure batch size down from 200..
A: When executing your batch job, pass in the optional parameter for batch size. i.e: Database.executeBatch(new BatchJob(), 10); will set your batch size to 10.
Q: Will we be able to do mixed DML operations with Custom Settings anytime soon?
A: In the upcoming release, custom settings will no longer be considered Setup objects for the purposes of mixed DML.
Q: Is it possible to query the last time a scheduled batch process completed?
A: Yes, you can query the CronTrigger table.
Q: How do I schedule a one time batch job, like 10 min from now?
A: You will have to schedule this job via the API using a cron expression.
Q: What are the governor limits for the schedulers?
A: same as async limits
Q: Which governor limits are applicable in batch apex: trigger or WSDL method?
A: Neither, it's a different (higher limit) set
Q: Can you have UI to see scheduled jobs
A: Yes, under Monitoring->Scheduled Jobs
Q: Can you have a UI for the Custom Settings
A: Yes, they can be used as standard controllers in VF as you would with a custom object, or with an Apex controller
Q: Can scheduled Apex tasks be packaged?
A: No, not at this time.