+ Start a Discussion
pavan 14pavan 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.
}

 
Jayabharathy LakshmananJayabharathy Lakshmanan

I am not seeing "BatchApexErrorEvent" in my org, what could be the reason?

Rajesh Yandrathi 1Rajesh Yandrathi 1
@Jayabharathy Lakshmanan 
Install the unmanaged package mentioned in the Module and try to edit it and create a trigger as requested
hemant kumar berahemant kumar bera
Hi Pavan,

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) 
Jayabharathy LakshmananJayabharathy Lakshmanan
Rajesh and Hemant - Thanks for answering my questions, this package is already installed before i raise my question, not seeing the BatchApexErrorEvent , will analyze it when get time. Thanks.
Sathyanarayana Borugula 8Sathyanarayana Borugula 8
@lakshmanan, This Object  will be available versions 44.0 & above. For fields and SOAP API to access this object please check this link."https://developer.salesforce.com/docs/atlas.en-us.222.0.platform_events.meta/platform_events/sforce_api_objects_batchapexerrorevent.htm
Jayabharathy LakshmananJayabharathy Lakshmanan
I was searching this "BatchApexErrorEvent" object in Org, i could see it in Developer console. My issue is resolved now, thanks for your answers.
Mamun Abdullah 11Mamun Abdullah 11
Hi all, can you help me please to find out the "Find BatchLeadConvert Class and just implement" in which area can I get it in my developer org?
 
Shivangi VermaShivangi Verma
Hi, 
I am getting the following error 
 
When executed, the BatchLeadConvertTest test class has test failures. All tests should pass.

I did everything just as you suggested.
shikha tiwari 40shikha tiwari 40
@Jayabharathy Lakshmanan
how did you find the object  "BatchApexErrorEvent "
Swati Patel 28Swati Patel 28
When executed, the BatchLeadConvertTest test class has test failures. All tests should pass.

I did everything just as you suggested.
Shivangi VermaShivangi Verma
@Swati I created a new trailhead playground and tried the code mentioned above in that. It worked for me. Please create a new playground and try. 
Thanks
Shivangi
sriram kanaparthisriram kanaparthi
@Swati Patel 28:  Even I got the Same Error "BatchLeadConvertTest test class has test failures. All tests should pass."
But when I created a new Trailhead playground like @Shivangi Verma Mentioned....It wroked for me. 

Thanks,
Sriram.
sujith k 3sujith k 3
Hi All,  Can anyone help me with the Platform Developer I Certification Maintenance (Winter '20). I am facing error " We couldn't find a lightning web component named 'myComponent". Help me iwth the steps