-
Notifications
You must be signed in to change notification settings - Fork 0
/
Add-Record-Types.apex
26 lines (23 loc) · 965 Bytes
/
Add-Record-Types.apex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
Script to update record types based on a picklist field. Uses the Schema and RecordTypeInfo
Classes to get the record types in a flexible way where you can use the record type labels
for assignment
*/
Schema.DescribeSObjectResult descAcct = Schema.SObjectType.Account;
Map<String,Schema.RecordTypeInfo> rtMapByName = descAcct.getRecordTypeInfosByName();
List<Account> accts = [SELECT Id, RecordTypeId, Type
FROM Account
WHERE RecordTypeID = NULL
LIMIT 10000];
for (Account a : accts) {
if(a.Type.contains('Partner')) {
a.RecordTypeId = rtMapByName.get('Partner').getRecordTypeId(); // Partner
}
else if (a.Type.equals('Customer - Direct')) {
a.RecordTypeId = rtMapByName.get('Customer - Direct').getRecordTypeId(); // Customer Direct
}
else {
a.RecordTypeId = rtMapByName.get('Customer').getRecordTypeId(); // Customer
}
}
update accts;