1

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. – John Thompson Jan 9 '17 at 20:41
  • 3
    Oh please oh please don't store your users initial passwords in a plain text field! – Christian Carter Jan 9 '17 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 '17 at 12:54
4

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.

| improve this answer | |
  • Thanks John! I think we have done something similar in another apex class. This should work! – abhi Jan 10 '17 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.