I wrote a Go library called batchforce to make scripting these types of updates easy without having to create a batch apex class.
It takes SOQL query and a function that maps an input record to update records. It uses the Bulk API to perform updates so it's pretty quick in most cases.
Here's the example from the README that updates the Title on all Contacts based on their Birthdate:
package main
import (
batch "github.com/octoberswimmer/batchforce"
force "github.com/ForceCLI/force/lib"
"time"
)
var (
fiftyYearsAgo = time.Now().AddDate(-50, 0, 0)
thirtyYearsAgo = time.Now().AddDate(-30, 0, 0)
)
func main() {
query := `
SELECT
Id,
Birthdate
FROM
Contact
WHERE
Birthdate != null
`
batch.Run("Contact", query, setTitle)
}
func setTitle(record force.ForceRecord) (updates []force.ForceRecord) {
birthdate, err := time.Parse("2006-01-02", record["Birthdate"].(string))
if err != nil {
return
}
update := force.ForceRecord{}
update["Id"] = record["Id"].(string)
switch {
case birthdate.Before(fiftyYearsAgo):
update["Title"] = "Geezer"
updates = append(updates, update)
case birthdate.After(thirtyYearsAgo):
update["Title"] = "Whippersnapper"
updates = append(updates, update)
}
return
}