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
srashti jain 10srashti jain 10 

help me in this test class for a custom controller

public with sharing class DataTableController {
    public static DataTableWrapper initRecords(String ObjectName, String fieldSetName, String Orderby, String OrderDir) {
        DataTableWrapper dtw = new DataTableWrapper();
        List<LabelDescriptionWrapper> labelList = new List<LabelDescriptionWrapper>();
        List<String> fieldSet = new List<String>();
        Set<String> fieldNameSet = new Set<String>(getFieldSet(ObjectName, fieldSetName).split(','));
        if(Schema.getGlobalDescribe().containsKey(ObjectName) ) {
            //sObject sObj = Schema.getGlobalDescribe().get(ObjectName).newSObject() ;
            //get all the labels for sObject fields and put them in a map, keyed to the field api name
            Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(ObjectName).getDescribe().fields.getMap();
            //fieldmap contains all fields name of an sObject in proper naming case.
            Map<Schema.SObjectField,String> fieldToAPIName = new Map<Schema.SObjectField,String>();
            Map<String, String> apiNameToLabel = new Map<String, String>();
            Boolean loopFlag = false;
            for(String fieldName :  fieldNameSet){
                if(loopFlag == false && fieldMap.containsKey(fieldName)){
                    labelList.add(new LabelDescriptionWrapper(fieldMap.get(fieldName).getDescribe().getLabel(), 
                                                              fieldName == 'Name' ? 'LinkName' : fieldName,  
                                                              new typeAttributesWR(new labelWR(fieldName), '_self'),
                    loopFlag = true; 
                if(fieldMap.containsKey(fieldName)) {
                    //labelList.add(new LabelDescriptionWrapper(fieldMap.get(fieldName).getDescribe().getLabel(), fieldName, fieldMap.get(fieldName).getDescribe().getType().name().toLowerCase(), true ));
                    labelList.add(new LabelDescriptionWrapper(fieldMap.get(fieldName).getDescribe().getLabel(), 
                                                              'text', null,
                                                              true ));
            //call method to query
            List<sObject> sObjectRecords = getsObjectRecords(ObjectName, fieldSet, 20, '', Orderby, OrderDir);
            system.debug('labelList '+labelList);
            dtw.ldwList     = labelList;
            dtw.sobList     = sObjectRecords;
            dtw.fieldsList     = fieldSet;
            dtw.totalCount  = Database.countQuery('SELECT count() FROM '+ObjectName);
        //returns wrapper datatype and fieldset fields properties.
        return dtw;
    public static List<sObject> getsObjectRecords(String ObjectName, List<String> fieldNameSet, Integer LimitSize, String recId, String Orderby, String OrderDir) {
        OrderDir = String.isBlank(OrderDir) ? 'asc' : OrderDir;
        String query = 'SELECT '+String.join(fieldNameSet, ',')+' FROM '+ObjectName;
        if(String.isNotBlank(recId)) {
            recId = String.valueOf(recId);
            query += ' WHERE ID >: recId ';
        query += ' ORDER BY '+Orderby+' '+OrderDir+' NULLS LAST';
        if(LimitSize != null && Integer.valueOf(LimitSize) > 0) {
            LimitSize = Integer.valueOf(LimitSize);
            query += ' Limit '+LimitSize;
        //this will return all the sObject records with all fieldset fields values.
        return Database.query(query);
    //get api name of the fields of a fieldset
    public static String getFieldSet(String sObjectName, String fieldSetName) {
        String result = '';
        SObjectType objToken = Schema.getGlobalDescribe().get(sObjectName);//metadata 
        Schema.DescribeSObjectResult d = objToken.getDescribe();
        Map<String, Schema.FieldSet> FieldsetMap = d.fieldSets.getMap();//<fset name, label>
        system.debug('objToken+++++++++'+objToken);//returns the name of the sobject.
            for(Schema.FieldSetMember f : FieldsetMap.get(fieldSetName).getFields()) {
                    result += ',';
                result += f.getFieldPath();
        system.debug('result *****'+result);
        return result ;//returns the name of the fields in  a fieldset.

    public class DataTableWrapper {
        public List<LabelDescriptionWrapper> ldwList;
        public List<sObject> sobList;
        public List<String> fieldsList;
        public Integer totalCount;
    public class LabelDescriptionWrapper {
        public String label;
        public String fieldName;
        public String type;
        public typeAttributesWR typeAttributes;
        public boolean sortable;        
        public LabelDescriptionWrapper(String labelTemp, String fieldNameTemp, String typeTemp,  typeAttributesWR typeAttributesTemp, boolean sortableTemp) {
            label       = labelTemp;
            fieldName = fieldNameTemp;
            type       = typeTemp;
            typeAttributes = typeAttributesTemp;
            sortable  = sortableTemp;            
    } // end LabelDescriptionWrapper
    public class labelWR {
        public String fieldName;
        public labelWR(String fieldNameTemp){
            fieldName = fieldNameTemp;
    public class typeAttributesWR {
        public labelWR label;
        public String target;
        public typeAttributesWR(labelWR labelTemp, String targetTemp){
            label = labelTemp;
            target = targetTemp;
mik Permik Per
The gradesfixer ( amazingly has good customer service and very talented writers. If there are issues with your order they will make it right, unlike some unscrupulous outfits. Most of the writers are true wordsmiths and write with great strength and imagery; all talk American English as their first language, and as a result there are no choppy, nonsensical submissions.