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
Heather_HansonHeather_Hanson 

Test class for record type selector component

I’m having trouble with my test class…not sure what I’m doing wrong, but I’m getting the following errors:
Illegal assignment from Map to List (line 6)
Method does not exist or incorrect signature: void getRecTypeId(String) from the type RecordTypeSelector (line 11)

My test class is for a custom record type selector component on my Asset object for my customer object OrderProject__c.

Any help would be appreciated!!
 
@isTest
public class TestRecordTypeSelector {


static testmethod void testFetchRecordTypes() {
    List<String> value = RecordTypeSelector.fetchRecordTypeValues('Asset');
  }

 static testmethod void testgetRecordTypeId() {
    String recordTypeLabel = 'Avaya';
    ID testId = RecordTypeSelector.getRecTypeId(recordTypeLabel);
    System.assert(testId != null);
  }
}

 
Maharajan CMaharajan C
Hi Heather,

Can you please post the Apex Class: RecordTypeSelector .

It will help us to solve your issue.

Thanks,
Maharajan.C
Heather_HansonHeather_Hanson
Yes! Here you go:
 
public class RecordTypeSelector{


    public static Map<Id, String> recordtypemap;

@AuraEnabled        

    public static Map<Id, String> fetchRecordTypeValues(String objectName){

        List<Schema.RecordTypeInfo> recordtypes = Schema.getGlobalDescribe().get(objectName).getDescribe().getRecordTypeInfos();    

        recordtypemap = new Map<Id, String>();

        for(RecordTypeInfo rt : recordtypes){

            if(rt.getName() != 'Master' && rt.getName().trim() != '')

            recordtypemap.put(rt.getRecordTypeId(), rt.getName());

        }        

        return recordtypemap;

    }

}

 
Maharajan CMaharajan C
Hi Heather,

Try the below changes in test class:

@isTest
public class TestRecordTypeSelector {
 static testmethod void testFetchRecordTypes() {
    Map<Id, String> value = RecordTypeSelector.fetchRecordTypeValues('Asset');
  }
}

In your above post i can see only the fetchRecordTypeValues method what about getRecTypeId method is it needed or not?

Thanks,
Maharajan.C


 
Heather_HansonHeather_Hanson
Yes, I think that I need to reference an ID, but I'm really not sure...here is the latest error. 

Method does not exist or incorrect signature: void getRecTypeId(String) from the type RecordTypeSelector

I think I may need to review the whole component too though because the pop-up is happening when I press my quick action and my list of Record Types is supplied, but I can't save because I'm getting the following error even though I'm populating the Asset ID:

No access to field AssetId. Either the field was removed from the entity or access to this field was removed.

Maybe I just need to start my weekend, but any help or feedback you can provide would be greatly appreciated!!