This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Task> tasks = | |
[SELECT Id, | |
WhatId, | |
TypeOf What | |
WHEN Account THEN BillingState, BillingCity | |
END | |
FROM Task | |
WHERE WhatId In (SELECT Id | |
FROM Account)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT Id, | |
WhatId, | |
TypeOf What | |
WHEN Account THEN BillingState, BillingCity | |
END | |
FROM Task | |
WHERE WhatId In (SELECT Id | |
FROM Account) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT Id, | |
WhatId, | |
What.Name, | |
What.BillingState | |
FROM Task | |
WHERE WhatId In (SELECT Id | |
FROM Account) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
public class OCRServiceTest { | |
@isTest | |
static void runOCRRollupsTest() { | |
Test.enableChangeDataCapture(); | |
Account acct = new Account(Name = 'Metillium Inc'); | |
insert acct; | |
Contact c1 = new Contact( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger OCRChangeEventTrigger on OpportunityContactRoleChangeEvent (after insert) { | |
new OCRService().runOCRRollups(Trigger.New); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public without sharing class OCRService { | |
public void runOCRRollups(List<OpportunityContactRoleChangeEvent> changeEvents) { | |
Set<String> oppContactRoleIds = new Set<String>(); | |
for (OpportunityContactRoleChangeEvent evt : changeEvents) { | |
EventBus.ChangeEventHeader header = evt.ChangeEventHeader; | |
oppContactRoleIds.addAll(new Set<String>(header.recordids)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger AccountTrigger on Account (after delete, after insert, after undelete, after update, before delete, before insert, before update) { | |
new AccountTriggerHandler().run(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class AccountTriggerHandler extends TriggerHandlerBase { | |
protected override void beforeInsert(List<Sobject> newRecords) { | |
List<Account> newAccounts = (List<Account>) newRecords; | |
for (Account newAcct : Trigger.new) { | |
if (newAcct.Name == ‘bad’) | |
newAcct.addError(‘Bad Name’); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger myAccountTrigger on Account (before delete, before update) { | |
if (Trigger.isBefore) { | |
if (Trigger.isUpdate) { | |
for (Account newAcct : Trigger.new) { | |
Account oldAcct = Trigger.oldMap.get(newAcct.Id); | |
if (oldAcct.Name != newAcct.Name && | |
newAcct.Name.containsIgnoreCase(‘Luke’) | |
newAcct.addError(‘Choose a better name’); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger myAccountTrigger on Account (before delete, before insert) { | |
if (Trigger.isBefore) { | |
if (Trigger.isInsert) { | |
for (Account newAcct : Trigger.new) { | |
if (newAcct.Name == ‘bad’) | |
newAcct.addError(‘Bad Name’); | |
} | |
} | |
} | |
} |
NewerOlder