You need to sign in to do that
Don't have an account?
pavan 14
Platform Developer I Certification Maintenance (Summer '19) Challenge Code
Platform Developer I Certification Maintenance (Summer '19) Challenege code
********************************************************************************
Modify an existing batch Apex job to raise BatchApexErrorEvents
Take an existing batch Apex job class and update it to implement the Database.RaisesPlatformEvents interface. Then, add a trigger on BatchApexErrorEvent that logs exceptions in the batch job to a custom object.
Update the BatchLeadConvert class to implement the Database.RaisesPlatformEvents marker interface.
Create an Apex trigger called BatchApexErrorTrigger on the BatchApexErrorEvent SObject type. For each event record, capture the following fields and save them to the corresponding fields in a new BatchLeadConvertErrors__c record.
AsyncApexJobId: AsyncApexJobId__c
JobScope: Records__c
StackTrace: StackTrace__c
To make the trigger bulk safe, use a single DML statement to insert a list of new records at the end.
****************************************************************
trigger BatchApexErrorTrigger on BatchApexErrorEvent (after insert) {
list<BatchLeadConvertErrors__c> bcr= new List<BatchLeadConvertErrors__c>();
for(BatchApexErrorEvent event: trigger.new){
BatchLeadConvertErrors__c evrterror= new BatchLeadConvertErrors__c ();
evrterror.AsyncApexJobId__c= event.AsyncApexJobId;
evrterror.Records__c=event.JobScope;
evrterror.StackTrace__c=event.StackTrace;
bcr.add(evrterror);
}
if(bcr.size()>0){
insert bcr;
}
}
*************************************************************
BatchLeadConvert Apex Batch Class
public with sharing class BatchLeadConvert implements Database.Batchable<SObject>, Database.RaisesPlatformEvents{
// Not be bothered whats here. Just Implement Raises Platform Events Interface.
}
********************************************************************************
Modify an existing batch Apex job to raise BatchApexErrorEvents
Take an existing batch Apex job class and update it to implement the Database.RaisesPlatformEvents interface. Then, add a trigger on BatchApexErrorEvent that logs exceptions in the batch job to a custom object.
Update the BatchLeadConvert class to implement the Database.RaisesPlatformEvents marker interface.
Create an Apex trigger called BatchApexErrorTrigger on the BatchApexErrorEvent SObject type. For each event record, capture the following fields and save them to the corresponding fields in a new BatchLeadConvertErrors__c record.
AsyncApexJobId: AsyncApexJobId__c
JobScope: Records__c
StackTrace: StackTrace__c
To make the trigger bulk safe, use a single DML statement to insert a list of new records at the end.
****************************************************************
trigger BatchApexErrorTrigger on BatchApexErrorEvent (after insert) {
list<BatchLeadConvertErrors__c> bcr= new List<BatchLeadConvertErrors__c>();
for(BatchApexErrorEvent event: trigger.new){
BatchLeadConvertErrors__c evrterror= new BatchLeadConvertErrors__c ();
evrterror.AsyncApexJobId__c= event.AsyncApexJobId;
evrterror.Records__c=event.JobScope;
evrterror.StackTrace__c=event.StackTrace;
bcr.add(evrterror);
}
if(bcr.size()>0){
insert bcr;
}
}
*************************************************************
BatchLeadConvert Apex Batch Class
public with sharing class BatchLeadConvert implements Database.Batchable<SObject>, Database.RaisesPlatformEvents{
// Not be bothered whats here. Just Implement Raises Platform Events Interface.
}
I am not seeing "BatchApexErrorEvent" in my org, what could be the reason?
Install the unmanaged package mentioned in the Module and try to edit it and create a trigger as requested
Follow the steps :
1) Install the package - https://login.salesforce.com/packaging/installPackage.apexp?p0=04t4P000002EMv0
2) Create new trigger from developer console and select BatchApexErrorEvent sobject
3) Copy and Paste below code
trigger BatchApexErrorTrigger on BatchApexErrorEvent (after insert) {
list<BatchLeadConvertErrors__c> bcr= new List<BatchLeadConvertErrors__c>();
for(BatchApexErrorEvent event: trigger.new){
BatchLeadConvertErrors__c evrterror= new BatchLeadConvertErrors__c ();
evrterror.AsyncApexJobId__c= event.AsyncApexJobId;
evrterror.Records__c=event.JobScope;
evrterror.StackTrace__c=event.StackTrace;
bcr.add(evrterror);
}
if(bcr.size()>0){
insert bcr;
}
}
4) Find BatchLeadConvert Class and just implement "Database.RaisesPlatformEvents" like below
public with sharing class BatchLeadConvert implements Database.Batchable<SObject>, Database.RaisesPlatformEvents{
//Just Implement Raises Platform Events Interface.
}
Please mark as the best answer.
Thanks
Hemant Kumar Bera
(Salesforce Certified Architect)
I am getting the following error
I did everything just as you suggested.
how did you find the object "BatchApexErrorEvent "
I did everything just as you suggested.
Thanks
Shivangi
But when I created a new Trailhead playground like @Shivangi Verma Mentioned....It wroked for me.
Thanks,
Sriram.