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
Akhil Katkam 5Akhil Katkam 5 

How to Write Test Class for this given code

Hi Developer Community, 

please help me with this code to be written in test class 
public class competingclass {
@AuraEnabled
public static List<ciboostc1501__Competition__c> getDetails(string rec){
 return [SELECT ciboostc1501__Persona1__c, ciboostc1501__Persona2__c , ciboostc1501__Persona3__c, ciboostc1501__Key_message_1__c, ciboostc1501__Key_message_2__c, ciboostc1501__Key_message_3__c
   FROM ciboostc1501__Competition__c where id=:rec];
  
}
}
please help me with the code , 
Thanks in Advance
 
Best Answer chosen by Akhil Katkam 5
CharuDuttCharuDutt
Hii Akhill Katkam
Try Below Code
@istest
Public Class UnitTest{
@isTest
Public Static Void UnitTest(){

ciboostc1501__Competition__c cc = new ciboostc1501__Competition__c();
cc.ciboostc1501__Persona1__c = 'Test1';
cc.ciboostc1501__Persona2__c = 'Test2';
cc.ciboostc1501__Persona3__c = 'Test3';
cc.ciboostc1501__Key_message_1__c = 'Message1';
cc.ciboostc1501__Key_message_2__c = 'Message2';
cc.ciboostc1501__Key_message_3__c = 'Message3';
Insert cc;
competingclass.getDetails(cc.Id);
}
}
Please Mark It As Best Answer If It Helps
Thank You!

 

All Answers

CharuDuttCharuDutt
Hii Akhill Katkam
Try Below Code
@istest
Public Class UnitTest{
@isTest
Public Static Void UnitTest(){

ciboostc1501__Competition__c cc = new ciboostc1501__Competition__c();
cc.ciboostc1501__Persona1__c = 'Test1';
cc.ciboostc1501__Persona2__c = 'Test2';
cc.ciboostc1501__Persona3__c = 'Test3';
cc.ciboostc1501__Key_message_1__c = 'Message1';
cc.ciboostc1501__Key_message_2__c = 'Message2';
cc.ciboostc1501__Key_message_3__c = 'Message3';
Insert cc;
competingclass.getDetails(cc.Id);
}
}
Please Mark It As Best Answer If It Helps
Thank You!

 
This was selected as the best answer
Suraj Tripathi 47Suraj Tripathi 47

Hi,

 

@isTest
  public class competingclass {
  
  public static testMethod void getDetailsTest(){
  
  ciboostc1501__Competition__c  obj=new ciboostc1501__Competition__c();
  obj.ciboostc1501__Persona1__c='Test';
  obj.ciboostc1501__Persona2__c ='Data';
  obj.Name='Salesforce';
  insert obj;//insert All required field
  
  Test.startTest();
  competingclass.getDetails(obj.id);
  Test.stopTest();
  
  }
  
  }


Please mark it as The Best Answer if it Helps you

Thank You

mukesh guptamukesh gupta
Hi Akhil,

Please use below code:
@isTest
private class MyTestClass {
    @isTest static void myTest() {
       ciboostc1501__Competition__c compObj = new ciboostc1501__Competition__c();
        compObj.ciboostc1501__Persona1__c = 'person1';
        compObj.ciboostc1501__Persona2__c = 'person1';
        compObj.ciboostc1501__Persona3__c = 'person1';
        compObj.ciboostc1501__Key_message_1__c= 'message1';
        compObj.ciboostc1501__Key_message_2__c= 'message2';
        compObj.ciboostc1501__Key_message_3__c = 'message3'; 
        
        insert compObj;
        competingclass.getDetails(compObj.id);
    }
}

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
Akhil Katkam 5Akhil Katkam 5
Thanks CharuDutt , actually fields are formula fields ,with ur code i can clear the issue