Get Hands-on Using Platform Events from Batch Apex Classes
Requirement : 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.
Solution
Hello,
What is the BatchLeadConvert test class please? :/
Thanks
Please follow the trail and Install Appexchsnge package, then make these changes.
The appexchange package contains the test classes.
It’s working. Thank you so much for your job ! Have a good day
How did you resolve the test class? I installed the package, updated the Apex Class but I still have issues with my test.
What error you’re getting?
I am getting the error :
When executed, the BatchLeadConvertTest test class has test failures. All tests should pass.
Can you share the Error/Screenshot on RUN TEST for BatchLeadConvertTest Class in Dev Console.
Make sure you have added BatchApexErrorTrigger class.
Here is what it says to me
https://prnt.sc/p6lu4g
Can you please show me the error of insert failed.
As Line 28 is an insertion for a Lead record, this shouldn’t be a problem.
I got “The ‘BatchApexErrorTrigger’ could not be found”
Please follow the trail and Install Appexchange package, then make these changes.
The appexchange package contains the test classes.
I was looking through some of your articles on this site and I conceive this website is rattling instructive! Retain putting up.
I think this is one of the most vital information for me. And i’m glad reading your article. But want to remark on some general things, The site style is perfect, the articles is really great : D. Good job, cheers
I got error whenever i execute the challenge No Apex class named ‘BatchLeadConvert’ was found. Refer to the setup instructions and install the unmanaged package.
Make sure you’ve installed App-exchange package mentioned in trail before making these changes.
You are right, I was not able to install that in Trailhead Playground. I was able to install that one in Developer Org only.
S
Sounds great. Thank you Siva for the update.
iam not able to install the package in my developer account.How to ressolve this error:
This app can’t be installed.
There are problems that prevent this package from being installed.
Illegal assignment from List to Apexclass BatchLeadConvertTest: Illegal assignment from List to Apexclass
Variable does not exist: body BatchLeadConvertTest: Variable does not exist: body
Hi,
Make sure you’ve copied an pasted code correctly.
Plus, Install the appexchange package first before these changes.