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
Narendhar Reddy YenuguNarendhar Reddy Yenugu 

how to write test class for this schema Class

public with sharing class CaseLwc {
public CaseLwc() {
}
@AuraEnabled(cacheable=true)
public static List<FetchValueWrapper> getPicklistValues(sObject objInfo,string picklistFieldApi){
Schema.DescribeSObjectResult objDescribe = objInfo.getSObjectType().getDescribe();
Map< string, Schema.SObjectField> fieldMap= objDescribe.fields.getMap();
List<Schema.picklistEntry> values=fieldMap.get(picklistFieldApi).getDescribe().getPicklistValues();
system.debug('values-----'+values);
List<FetchValueWrapper> objWrapper=new List<FetchValueWrapper>();
for(Schema.picklistEntry p:values){
FetchValueWrapper fw = new FetchValueWrapper();
fw.slabel=p.getlabel();
fw.svalue=p.getvalue();
objWrapper.add(fw);
system.debug('Map-----'+objWrapper);
}
return objWrapper;
}
/* @AuraEnabled(cacheable=true)
public static List<String> getCaseFields(){
SObjectType caseType = Schema.getGlobalDescribe().get('Case');
Map<String,Schema.SObjectField> mfields = caseType.getDescribe().fields.getMap();
system.debug('fields------'+mfields);
List<String> sObjectDetailsList = new List<String>();
for(String s : mfields.keySet()){
sObjectDetailsList.add(String.valueOf(mfields.get(s)));
}
system.debug('sObjectDetailsList------'+sObjectDetailsList);
return sObjectDetailsList;
} */


@AuraEnabled(cacheable=true)
public static list<CaseWrapper> getCaseFields() {
list<string> fvlst = new list<string>();
list<CaseWrapper> lstwrp = new list<CaseWrapper>();
list<string> fieldvaluelst = new list<string>();
String obj = 'Case';
Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
Schema.SObjectType sobjType = gd.get(obj);
Schema.DescribeSObjectResult describeResult = sobjType.getDescribe();
Map<String,Schema.SObjectField> fieldsMap = describeResult.fields.getMap();
system.debug('fieldsMap---'+fieldsMap);
CaseWrapper cwrp = new CaseWrapper();
cwrp.AccountId = fieldsMap.get('AccountId').getDescribe().getLabel();
cwrp.CaseNumber = fieldsMap.get('CaseNumber').getDescribe().getLabel();
cwrp.AssetId = fieldsMap.get('AssetId').getDescribe().getLabel();
cwrp.Origin = fieldsMap.get('Origin').getDescribe().getLabel();
cwrp.OwnerId = fieldsMap.get('OwnerId').getDescribe().getLabel();
cwrp.Reason = fieldsMap.get('Reason').getDescribe().getLabel();
cwrp.SourceId = fieldsMap.get('SourceId').getDescribe().getLabel();
  cwrp.IsClosedOnCreate = fieldsMap.get('IsClosedOnCreate').getDescribe().getLabel();
cwrp.SuppliedName = fieldsMap.get('SuppliedName').getDescribe().getLabel();
cwrp.ContactEmail = fieldsMap.get('ContactEmail').getDescribe().getLabel();
cwrp.Status = fieldsMap.get('Status').getDescribe().getLabel();
cwrp.Type = fieldsMap.get('Type').getDescribe().getLabel();
cwrp.SuppliedPhone = fieldsMap.get('SuppliedPhone').getDescribe().getLabel();
cwrp.SuppliedEmail = fieldsMap.get('SuppliedEmail').getDescribe().getLabel();
cwrp.SuppliedCompany = fieldsMap.get('SuppliedCompany').getDescribe().getLabel();
cwrp.Subject = fieldsMap.get('Subject').getDescribe().getLabel();
cwrp.Priority = fieldsMap.get('Priority').getDescribe().getLabel();
cwrp.ContactFax = fieldsMap.get('ContactFax').getDescribe().getLabel();
cwrp.ContactMobile = fieldsMap.get('ContactMobile').getDescribe().getLabel();
cwrp.ContactId = fieldsMap.get('ContactId').getDescribe().getLabel();
cwrp.ContactPhone = fieldsMap.get('ContactPhone').getDescribe().getLabel();
cwrp.Description = fieldsMap.get('Description').getDescribe().getLabel();
cwrp.Comments = fieldsMap.get('Comments').getDescribe().getLabel();
cwrp.LastModifiedById = fieldsMap.get('LastModifiedById').getDescribe().getLabel();
cwrp.ParentId = fieldsMap.get('ParentId').getDescribe().getLabel();
cwrp.CreatedDate = fieldsMap.get('CreatedDate').getDescribe().getLabel();
cwrp.PotentialLiability = fieldsMap.get('PotentialLiability__c').getDescribe().getLabel();
cwrp.EngineeringReqNumber = fieldsMap.get('EngineeringReqNumber__c').getDescribe().getLabel();
cwrp.Product = fieldsMap.get('Product__c').getDescribe().getLabel();
cwrp.SLAViolation = fieldsMap.get('SLAViolation__c').getDescribe().getLabel();
lstwrp.add(cwrp);
system.debug('wrplist--'+lstwrp);
return lstwrp;
}

@AuraEnabled
public static void saveRecords(Case Obj) {
system.debug('obj'+ obj);
Insert Obj;
}
public with sharing class FetchValueWrapper {
@AuraEnabled public string slabel {get;set;}
@AuraEnabled public string svalue {get;set;}
}
}
ShirishaShirisha (Salesforce Developers) 

Hi Narendhar,

Greetings!

Unfortunately,it is very difficult to provide you the exact code to achieve your requirement.However,I can provide you the sample code which will help you in writing the test class.

Please check the below blog for sample code:

https://www.jitendrazaa.com/blog/tag/testclass/

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Shirisha Pathuri

Kallu KaliaKallu Kalia
Thanks bro, I was also having the same question. And you solved my problem.
Do you like christmas abbott, I like her so much.