CREATE trigger "SFDC_US_DEMO"."TRIGGER_CUST_REV_SQL"
AFTER INSERT OR UPDATE ON "SFDC_US_DEMO"."CUST_REV_SQL"
REFERENCING NEW ROW as newAccount
FOR EACH ROW
BEGIN
INSERT INTO "SFDC_US_DEMO"."VT_Account"("Name","SAP_Source_ID_c","BillingCity","BillingPostalCode","BillingStreet","AccountNumber","SDI_test_c")
VALUES(:newAccount."NAME",:newAccount."CUST_ID",:newAccount."CITY",:newAccount."POST_CODE",:newAccount."STREET",:newAccount."CUST_ID",'US_AGENT');
END;
CREATE TRIGGER "SFDC_US_DEMO"."TRIGGER_CUST_REV_SQL_PLATFORM_EVENT"
AFTER INSERT OR UPDATE ON "SFDC_US_DEMO"."CUST_REV_SQL"
REFERENCING NEW ROW NEWACCOUNT
FOR EACH ROW
BEGIN INSERT INTO "SFDC_US_DEMO"."SFDC_US_SANDBOX2_AccountContactEvent__e"("Account_Name__c","Contact_LastName__c","Account_ExtID__c","Account_BillingCity__c","Account_BillingStreet__c","Account_BillingZipcode__c","Contact_Title__c","Contact_Email__c","Account_BillingState__c")
VALUES(:newAccount.NAME,:newAccount.NAME,:newAccount.CUST_ID,:newAccount.CITY,:newAccount.STREET,:newAccount.POST_CODE,'Mr','test@advantco.com','NC');
END
trigger InsertAccountContactRecord on AccountContactEvent__e (after insert) {
List<Account> accts = new List<Account>();
List<Contact> conts = new List<Contact>();
Integer counter = 0;
String replayId = null;
for(AccountContactEvent__e event : Trigger.New) {
replayId = event.ReplayId;
// Increase batch counter.
counter++;
// Only process the first 200 event messages
if (counter > 200) {
// Resume after the last successfully processed event message
// after the trigger stops running.
// Exit for loop.
break;
}
Account a = new Account(
Name = event.Account_Name__c,
SAP_Source_ID__c = event.Account_ExtID__c,
BillingCity = event.Account_BillingCity__c,
BillingStreet = event.Account_BillingStreet__c,
BillingPostalCode = event.Account_BillingZipcode__c,
BillingState = event.Account_BillingState__c);
accts.add(a);
Contact c = new Contact(
LastName = event.Contact_LastName__c,
Email = event.Contact_Email__c,
Title = event.Contact_Title__c);
conts.add(c);
}
try {
// Insert Account records
Database.SaveResult[] srAccountList = Database.insert(accts, false);
List<String> accountIds = new List<String>();
for (Database.SaveResult sr : srAccountList) {
if (sr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
accountIds.add(sr.getId());
}
}
Integer i = 0;
for (Contact c : conts) {
c.AccountId = accountIds.get(i++);
}
// Insert Contact records
Database.SaveResult[] srContactList = Database.insert(conts, false);
List<String> contactIds = new List<String>();
for (Database.SaveResult sr : srContactList) {
if (sr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
contactIds.add(sr.getId());
}
}
// Set Replay ID after which to resume event processing
// in new trigger execution.
if (replayId != null) {
EventBus.TriggerContext.currentContext().setResumeCheckpoint(replayId);
}
} catch (DmlException e) {
System.debug('err: ' + e);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |