-
-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Christian G. Warden edited this page Nov 26, 2024
·
6 revisions
Freeze all users with specific profiles by updating UserLogin
records.
$ batchforce update UserLogin -q "SELECT Id FROM UserLogin WHERE UserId IN (SELECT Id FROM User WHERE Profile.Name IN ('Marketing', 'Customer Support'))" '{Id: record.Id, IsFrozen: true}'
Create new Notes from Tasks linked to specific SObject records by upserting ContentVersion
records.
batchforce upsert --external-id Migrated_From__c -b 10000 ContentVersion \
--query-all "SELECT Id, Description, CreatedDate, WhatId, CreatedBy.Name, CreatedById FROM Task WHERE Subject = 'Note' and What.Type = 'Inquiry__c' and What.RecordType.DeveloperName = 'Standard' and IsDeleted = false ORDER BY CreatedDate DESC" \
'{Title: "Note from " + record.CreatedBy.Name, FirstPublishLocationId: record.WhatId, CreatedById: record.CreatedById, CreatedDate: record.CreatedDate, PathOnClient: "Note from " + record.CreatedBy.Name + ".snote", VersionData: base64(escapeHtml(escapeUnicode(record.Description))), Migrated_From__c: record.Id}'
Get the value of a field from the most recent Opportunity for an Account and copy it up to the parent Account record.
$ batchforce update Account -q "SELECT Id, URL__c, Account.URL__c, AccountId FROM Opportunity WHERE URL__c != null AND Account.URL = null ORDER BY AccountId, CreatedDate desc" \
'incr(record.AccountId) > 1 ? nil : {Id: record.AccountId, URL__c: record.URL__c}'
$ batchforce update User --context "Id newRoleId = [SELECT Id FROM UserRole WHERE DeveloperName = 'New_Role'].Id;" \
-q "SELECT Id FROM User WHERE UserRole.DeveloperName = 'Old_Role'" \
'{Id: record.Id, UserRoleId: apex.newRoleId}'
Format CreatedDate
in custom fields for Day of Week (e.g. "01-Mon") and Hour Created using a user-agnostic Timezone.
$ batchforce update Lead -q "SELECT Id, CreatedDate, Division__r.Time_Zone__c FROM Lead WHERE Created_Day__c = null" \
'let t = date(record.CreatedDate, "2006-01-02T15:04:05.000-0700").In(timezone(record.Division__r.Time_Zone__c));
let day = "0" + string(int(t.Weekday()) + 1) + "-" + t.Format("Mon");
{Id: record.Id, Created_Day__c: day, Created_Hour__c: a.Format("15")}'
Set a custom Closed_By__c
field to the User who most recently updated the Stage of an Opportunity to "Closed Lost".
$ batchforce update Opportunity \
-q "SELECT Id, (SELECT CreatedById, NewValue FROM Histories WHERE Field = 'StageName' ORDER BY CreatedDate DESC) from Opportunity WHERE StageName = 'Closed Lost'" \
'let history = record.Histories ?? []; let update = filter(history, #.NewValue == "Closed Lost") | first(); update == nil ? nil : {Id: record.Id, Closed_By__c: update.CreatedById}'