+ Start a Discussion
Ajith Selvaraj 2Ajith Selvaraj 2 

Methods defined as TestMethod do not support getContent call in test class

public static workOrderRecordFormApex SAPgetPicklistValues(string recordTypeId, string objectName,string fieldApiName){
        Map<String, String>  piclistValues=new Map<String, String>();
        workOrderRecordFormApex objs = new workOrderRecordFormApex();
        Httprequest req = new HttpRequest();
        String pageContent = Page.SessionId.getContent().toString();
        Integer startIndex = pageContent.indexOf(SESSION_ID_START) + SESSION_ID_START.length();
        Integer endIndex = pageContent.indexOf(SESSION_ID_END);
        String sessionId =pageContent.substring(startIndex, endIndex);
            URL.getSalesforceBaseUrl().toExternalForm() +
            '/services/data/v50.0/ui-api/object-info/' +
            objectName +
            '/picklist-values/' +
            recordTypeId +
            '/' +
        req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
           req.setHeader('Authorization', 'Bearer ' + sessionId);
        Http http = new Http();
        httpresponse response=http.send(req);
        picklistWrapper obj=new picklistWrapper();
        obj=(picklistWrapper)JSON.deserialize(response.getBody(), picklistWrapper.class);
        String JSONstr = response.getBody();
        JSONParser parser = JSON.createParser(JSONstr);
        Map<String, Object> defaultValueMap = (Map<String, Object>)JSON.deserializeUntyped(JSONstr);
        for(piclistValues pickVal:obj.values){
            piclistValues.put(pickVal.value, pickVal.label);
        objs.defaultSAPOrderType = defaultValueMap.get('defaultValue');
        objs.sapOrderTypeValues = piclistValues;
        system.debug('objs' + objs);
        return objs;

    private static List<PicklistEntryWrapper> wrapPicklistEntries(List<Schema.PicklistEntry> PLEs) {
        return (List<PicklistEntryWrapper>)
            JSON.deserialize(JSON.serialize(PLEs), List<PicklistEntryWrapper>.class);
    public class picklistWrapper{
        @AuraEnabled public piclistValues[] values;
    public class piclistValues {
        @AuraEnabled public String label;    
        @AuraEnabled public String value;
    public class PicklistEntryWrapper{
        public String active {get;set;}
        public String defaultValue {get;set;}
        public String label {get;set;}
        public String value {get;set;}
        public String validFor {get;set;}
        public PicklistEntryWrapper(){            
    public object defaultSAPOrderType {get; set;}
    public Map<String, String> sapOrderTypeValues {get; set;}
    public class SObJectResult {
        public String recName;
        public Id recId;
        public SObJectResult(String recNameTemp, Id recIdTemp) {
            recName = recNameTemp;
            recId = recIdTemp;

In this above code Im getting the picklist value for field, where the values is based on record type, the code is working fine, But for the test class Im calling that method like 
QuoteComponentCtrl.SAPgetPicklistValues(salesRecordTypeId, 'WorkOrder', 'SAP_Order_Type__c');
But Im getting error as Methods defined as TestMethod do not support getContent call. I have created on vf page name as SessionId to get the end point. Kindly help me to resolve the error in test class
ShivankurShivankur (Salesforce Developers) 
Hi Ajith,

You may consider writing your test class using mock callouts .Never use get content inside test class.

Please refer to below developer guide to implement a Test class for methods with Webservice callout in Apex:

More reference:

Hope above information helps, Please mark as Best Answer so that it can help others in the future.