function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sumit dsumit d 

Test class for workBadge

Hi All, 
   I have a class mentioned below:-
public without sharing class CreateBadgeController {
    @AuraEnabled 
    public static WorkBadge createBadge(Map<String, Object> callObject) {
     List<WorkBadgeDefinition> workBadges= [SELECT Id 
                                               FROM WorkBadgeDefinition 
                                               where Name = 'Thanks'];
        String workBadgeDefinationId= String.valueOf (workBadges.get(0).id);
        
        WorkThanks  wrkThanks  = new WorkThanks();
        wrkThanks.GiverId       = UserInfo.getUserId();
        wrkThanks.Message    = 'Thanks';
        wrkThanks.OwnerId     = UserInfo.getUserId();
        wrkThanks.how_did_person_help_you__c = String.valueOf(callObject.get('how_did_person_help_you__c'));
        wrkThanks.Describe_your_connection__c = String.valueOf(callObject.get('Describe_your_connection__c'));
        wrkThanks.How_has_this_connection_impacted_you__c = String.valueOf(callObject.get('How_has_this_connection_impacted_you__c'));
        wrkThanks.Notes__c = String.valueOf(callObject.get('Notes__c'));
        //wrkThanks.NetworkId = '0DB8c0000001peoGAA';
        wrkThanks.NetworkId = System.Label.CommunityId;
        Insert wrkThanks;
        
        WorkBadge  wrkBadge = new WorkBadge ();
        wrkBadge.DefinitionId = workBadgeDefinationId;
        //wrkBadge.RecipientId = '0058c000009g2waAAA';
        wrkBadge.RecipientId = String.valueOf(callObject.get('RecipientId'));
        wrkBadge.SourceId = wrkThanks.Id;
        wrkBadge.NetworkId =  System.Label.CommunityId;
        Insert wrkBadge;
        return wrkBadge;
    }
}
I am trying to create a test class for it which is giving me error my test class is given below:-
@istest
public class CreateBadgeControllerTest {
    Public Static testmethod void createWorkBadgeTest(){
   
        WorkThanks  wrkThanks  = new WorkThanks();
        wrkThanks.GiverId = UserInfo.getUserId();
        wrkThanks.Message = 'Thanks';
        wrkThanks.OwnerId = UserInfo.getUserId();
        wrkThanks.how_did_person_help_you__c = 'Provided me a connection';
        wrkThanks.Describe_your_connection__c =  'New Friend/ Colleague';
        wrkThanks.How_has_this_connection_impacted_you__c = 'Revenue Growth';
        wrkThanks.Notes__c =  'Thanks test';
        //wrkThanks.NetworkId = '0DB8c0000001peoGAA';
        wrkThanks.NetworkId = System.Label.CommunityId;
        Insert wrkThanks;
        WorkBadge  wrkBadge = new WorkBadge ();
        wrkBadge.DefinitionId = '0W18c000001Cm4pCAC';
        //wrkBadge.RecipientId = '0058c000009g2waAAA';
        wrkBadge.RecipientId =  userinfo.getUserId();
        wrkBadge.SourceId = wrkThanks.Id;
        wrkBadge.NetworkId =  System.Label.CommunityId;
        Insert wrkBadge;
        
        Map<String, WorkBadge> callObject = new Map<String, WorkBadge>();
        callObject.put(wrkBadge.id,wrkBadge);
           CreateBadgeController.createBadge(callObject);
        test.stopTest();
    }
}
its giving me error:- System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ID_FIELD, Invalid input badge definition id.: []
Can anyone help me out how to create test class for it?
sumit dsumit d
I have created the test class with 95% coverage but i ma getting this error:- Internal Salesforce Error: 916435169-539865 (-1714358592) (-1714358592)
What could be the issue here?
My test class is given below:- 
@istest
private without sharing class CreateBadgeControllerTest {
    Static TestMethod void createWorkBadgeTest(){
        
        WorkBadgeDefinition  wrkDef=new WorkBadgeDefinition();
        wrkDef.Name='Thanks';
        wrkDef.Description='Test Description';
        wrkDef.ImageUrl = 'https://corporateconnections.my.salesforce.com/img/rypple/Thanks.png';
        wrkDef.IsActive=True;
        Insert wrkDef;
        Map<String, Object> callObject = new Map<String, Object>();
        String str = 'how_did_person_help_you__c';
        Object obj = 'Provided me a connection';
        callObject.put('how_did_person_help_you__c','Provided me a connection');
        callObject.put('Describe_your_connection__c','New Friend/ Colleague');
        callObject.put('How_has_this_connection_impacted_you__c','Revenue Growth');
        
        CreateBadgeController.createBadge(callObject);
        test.stopTest();
    }
}