Skip to content

Commit 1f25175

Browse files
committed
Adjustments to provide better example of platform event subscription
1 parent aaaf4e0 commit 1f25175

File tree

7 files changed

+72
-10
lines changed

7 files changed

+72
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ temp/
77
**/dep-dir.txt
88
*.prefs
99
build.properties
10-
/sfdx-source/core/main/default
10+
/sfdx-source/other/main/default
1111

1212
# MavensMate IDE related
1313
*mm.log
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class AccountModsEventPublisher {
2+
public static void publishChangedAccount( Set<Id> accountIdSet ) {
3+
// Setup and save the AT4DXMessage__e
4+
AT4DXMessage__e platformEventbus = new AT4DXMessage__e();
5+
platformEventbus.EventName__c = 'ACCOUNT_RECORD_MODIFICATION';
6+
platformEventbus.Category__c = Account.getSObjectType().getDescribe().getName();
7+
8+
// Serialize the accountIdSet
9+
platformEventbus.Payload__c = JSON.serialize( accountIdSet );
10+
11+
Database.SaveResult sr = EventBus.publish(platformEventbus);
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>55.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

sfdx-source/reference-implementation-sales/main/classes/event-consumers/Sales_PlatformEventsConsumer.cls

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@
2626

2727
public class Sales_PlatformEventsConsumer extends PlatformEventAbstractConsumer {
2828
public override void runInProcess() {
29-
System.debug('<ojs> Sales_PlatformEventsConsumer.runInProcess');
30-
System.debug('<ojs> events:\n' + events);
31-
32-
Set<Id> idSet = new Set<Id>();
29+
Set<Id> accountIdSet = new Set<Id>();
3330

3431
for (SObject sobj : events) {
3532
AT4DXMessage__e evt = (AT4DXMessage__e) sobj;
36-
idSet.addAll((Set<Id>) JSON.deserialize(evt.Payload__c, Set<Id>.class));
33+
accountIdSet.addAll((Set<Id>) JSON.deserialize(evt.Payload__c, Set<Id>.class));
3734
}
3835

39-
System.debug('idSet:\n' + idSet);
36+
Sales_AccountsService.proocessAccountChanges(accountIdSet);
4037
}
4138
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) 2020, John M. Daniel, John Storey
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* - Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* - Neither the name of the John M. Daniel, nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software without
15+
* specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20+
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
**/
26+
27+
public class Sales_AccountsService
28+
{
29+
// private static IAccountsService service()
30+
// {
31+
// return (IAccountsService) Application.Service.newInstance( IAccountsService.class );
32+
// }
33+
34+
public static void proocessAccountChanges( Set<Id> accountIdSet )
35+
{
36+
37+
}
38+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="AccountsService">
3+
<apiVersion>55.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

sfdx-source/reference-implementation-sales/main/schema/customMetadata/PlatformEvents_Subscription.Sales_PlatformEventsConsumer.md-meta.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3-
<label>Sales - Platform Events Consumer</label>
3+
<label>Sales_PlatformEventsConsumer</label>
44
<protected>false</protected>
55
<values>
66
<field>Consumer__c</field>
@@ -16,14 +16,18 @@
1616
</values>
1717
<values>
1818
<field>Event__c</field>
19-
<value xsi:nil="true"/>
19+
<value xsi:type="xsd:string">ACCOUNT_RECORD_MODIFICATION</value>
20+
</values>
21+
<values>
22+
<field>Execute_Synchronous__c</field>
23+
<value xsi:type="xsd:boolean">false</value>
2024
</values>
2125
<values>
2226
<field>IsActive__c</field>
2327
<value xsi:type="xsd:boolean">true</value>
2428
</values>
2529
<values>
2630
<field>MatcherRule__c</field>
27-
<value xsi:type="xsd:string">MatchEventBusAndCategory</value>
31+
<value xsi:type="xsd:string">MatchEventBusAndCategoryAndEventName</value>
2832
</values>
2933
</CustomMetadata>

0 commit comments

Comments
 (0)