• Manjunath S 90
  • NEWBIE
  • 5 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 3
    Replies
I have a class something like this:

global void execute(Database.BatchableContext BC, List<OBJ__c> objList) {
        try{
            if(objList!= null && objList.size() > 0 ){
                delete objList;
            }
        }
        catch(Exception ex){
            System.debug('Exception');
        }
    }

My test class:

 List<OBJ__C> cartList = [SELECT id from OBJ__C LIMIT 1]; 
        Test.startTest();
        BATCH_CLASS deleteCartBatch = new BATCH_CLASS ();
        Database.executeBatch(deleteCartBatch, 200); 
        Test.stopTest();


How do I cover the catch block in this test class?

 
Hi Everyone,
I am getting issue while doing this LWC challenge - 
Use Lightning Data Service to Work with Data

ErrorWe can’t find an event handler named 'handleSuccess'.

Code -
contactCreator.Js
import { LightningElement,api,track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
//import CONTACT_OBJECT from '@salesforce/schema/Contact';
//import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName';
//import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName';
//import EMAIL_FIELD from '@salesforce/schema/Contact.Email';


export default class ContactCreator extends LightningElement {
    @api recordId;
    @api objectApiName;
    @track fields = ['FirstName', 'LastName', 'Email'];

    handleSuccess(event){
        
        const toastEvent = new ShowToastEvent({
            title: "Contact created",
            message: "Record ID: " + event.detail.id,
            variant: "success"
        });
        this.dispatchEvent(toastEvent);
    }

}
contactCreator.html
<template>
    <lightning-card>
        <lightning-record-form
            object-api-name={objectApiName}
            fields={fields}
            record-id={recordId} 
            onsuccess={handleSuccess}>
        </lightning-record-form>
    </lightning-card>
</template>

Please help me what i am doing wrong here as i have declared handleSuccess event in the JS .

Thanks,
I have a class something like this:

global void execute(Database.BatchableContext BC, List<OBJ__c> objList) {
        try{
            if(objList!= null && objList.size() > 0 ){
                delete objList;
            }
        }
        catch(Exception ex){
            System.debug('Exception');
        }
    }

My test class:

 List<OBJ__C> cartList = [SELECT id from OBJ__C LIMIT 1]; 
        Test.startTest();
        BATCH_CLASS deleteCartBatch = new BATCH_CLASS ();
        Database.executeBatch(deleteCartBatch, 200); 
        Test.stopTest();


How do I cover the catch block in this test class?