-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountTrigger.trigger
More file actions
42 lines (39 loc) · 1.45 KB
/
AccountTrigger.trigger
File metadata and controls
42 lines (39 loc) · 1.45 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
trigger AccountTrigger on Account (before insert, after insert) {
switch on Trigger.operationType {
when BEFORE_INSERT {
for (Account acc : Trigger.new) {
//Solution 1
if (acc.Type == null) {
acc.Type = 'Prospect';
}
//Solution 2
acc.BillingStreet = acc.ShippingStreet ?? '';
acc.BillingCity = acc.ShippingCity ?? '';
acc.BillingState = acc.ShippingState ?? '';
acc.BillingPostalCode = acc.ShippingPostalCode ?? '';
acc.BillingCountry = acc.ShippingCountry ?? '';
//Solution 3
if (acc.Fax != null && acc.Phone != null && acc.Website != null) {
acc.Rating = 'Hot';
}
}
}
when AFTER_INSERT {
//Solution 4
List<Contact> contactsToInsert = new List<Contact>();
for (Account acc : Trigger.new) {
Contact con = new Contact();
con.LastName = 'DefaultContact';
con.Email = 'default@email.com';
con.AccountId = acc.Id;
contactsToInsert.add(con);
}
if (contactsToInsert.size() > 0) {
insert contactsToInsert;
}
}
when else {
System.debug('AccountTrigger WHEN ELSE ACTIVATED');
}
}
}