We have a batch apex class that resets passwords for community users created by another process. One of our user requirements is to store the initial password in a custom field.

The user will get the password and she can then proceed to change this when she wants it.

System.resetPassword(userId); works well for us. Unfortunately this doesn't work well with bulkification if we have to do more than 150 users at a time.

So how do you reset the passwords, store the password and also bulkify the code at the same time?

  • Why would you want to store the initial password? It's probably best to simply allow the Force.com platform to handle that sort of thing. Jan 9, 2017 at 20:41
  • 3
    Oh please oh please don't store your users initial passwords in a plain text field! Jan 9, 2017 at 21:10
  • I wouldn't want to, but in order for a beautifully composed email to be sent out of the marketing cloud and also prevent users from self-registering, something like this had to be implemented. Also, the user does not see any data till she has RESET her password.
    – abhi
    Jan 10, 2017 at 12:54

1 Answer 1


Generally speaking, you can limit the number of records processed in an Apex Batch by passing in a scope parameter to the database.executeBatch(Object batchClassObject, Integer scope); method as described here. The Scope is an integer that limits the number of records passed to the execute method of the Batch Class. If your Batch job is SOQL heavy (for example) you could limit the number of records to avoid a "TOO MANY SOQL QUERIES" limit error.

  • Thanks John! I think we have done something similar in another apex class. This should work!
    – abhi
    Jan 10, 2017 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .