You need to sign in to do that
Don't have an account?
nbk
System.TypeException: Data type not supported in test class
Hello Everyone,
I am getting System.TypeException: Data type not supported in API 30.0 versions while running the same class is working in previous versions. Below are the sample class.
Class:
global class SampleUtility
{
public static Map<String , Boolean> searchMap = new Map<String , Boolean>() ;
public String createDynamicQuery(Set<String> selectClaseFields, SObject sObjectRecord)
{
Schema.SObjectType systemObjectType ;
////System.debug('sObjectRecord :::::: ' + sObjectRecord) ;
if(sObjectRecord != null)
{
systemObjectType = sObjectRecord.getSObjectType();
Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
String objectName = r.getLocalName();
if(objectName != null && objectName != '' && selectClaseFields != null && selectClaseFields.size() > 0)
{
//get operator for fields which have value in sObject
//Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
Map<String,Schema.SObjectField> M = r.fields.getMap();
Map<String,DisplayType> fieldMap = new Map<String,DisplayType>();
Set<String> existingFieldNamesList = M.keySet();
//Remove tag fields from fields name
for(String fieldName : existingFieldNamesList)
{
//String str = String.valueOf(sObjectRecord.get(fieldname));
//if(str != null && str != '' && str != '[]')
if(sObjectRecord.get(fieldname)!='[]' && sObjectRecord.get(fieldname)!=null && sObjectRecord.get(fieldname)!='') //throwing error
{
searchMap.put(objectName, true) ;
Schema.SObjectField field = M.get(fieldName);
Schema.DescribeFieldResult fieldDesc = field.getDescribe();
fieldMap.put(fieldName, fieldDesc.getType());
//Base_AC_Utility.selectedFieldLabel += fieldDesc.getLabel() + '-' + sObjectRecord.get(fieldname) + ' ,' ;
}
}
}
}return null;
}
}
Test Class
@isTest
public class Test_Utility
{
public static testMethod void unittest1()
{
Account acc = new Account(name='testaccount');
insert acc;
Contact contact = new Contact(accountid=acc.id,LastName='Test');
insert contact;
SampleUtility controller= new SampleUtility();
Set<String> selectClaseFields = new Set<String>{'Id','Name'};
String actualQuery1 = controller.createDynamicQuery(selectClaseFields,contact);
}
}
Please let me know if you have any workaround for this issue.
I am getting System.TypeException: Data type not supported in API 30.0 versions while running the same class is working in previous versions. Below are the sample class.
Class:
global class SampleUtility
{
public static Map<String , Boolean> searchMap = new Map<String , Boolean>() ;
public String createDynamicQuery(Set<String> selectClaseFields, SObject sObjectRecord)
{
Schema.SObjectType systemObjectType ;
////System.debug('sObjectRecord :::::: ' + sObjectRecord) ;
if(sObjectRecord != null)
{
systemObjectType = sObjectRecord.getSObjectType();
Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
String objectName = r.getLocalName();
if(objectName != null && objectName != '' && selectClaseFields != null && selectClaseFields.size() > 0)
{
//get operator for fields which have value in sObject
//Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
Map<String,Schema.SObjectField> M = r.fields.getMap();
Map<String,DisplayType> fieldMap = new Map<String,DisplayType>();
Set<String> existingFieldNamesList = M.keySet();
//Remove tag fields from fields name
for(String fieldName : existingFieldNamesList)
{
//String str = String.valueOf(sObjectRecord.get(fieldname));
//if(str != null && str != '' && str != '[]')
if(sObjectRecord.get(fieldname)!='[]' && sObjectRecord.get(fieldname)!=null && sObjectRecord.get(fieldname)!='') //throwing error
{
searchMap.put(objectName, true) ;
Schema.SObjectField field = M.get(fieldName);
Schema.DescribeFieldResult fieldDesc = field.getDescribe();
fieldMap.put(fieldName, fieldDesc.getType());
//Base_AC_Utility.selectedFieldLabel += fieldDesc.getLabel() + '-' + sObjectRecord.get(fieldname) + ' ,' ;
}
}
}
}return null;
}
}
Test Class
@isTest
public class Test_Utility
{
public static testMethod void unittest1()
{
Account acc = new Account(name='testaccount');
insert acc;
Contact contact = new Contact(accountid=acc.id,LastName='Test');
insert contact;
SampleUtility controller= new SampleUtility();
Set<String> selectClaseFields = new Set<String>{'Id','Name'};
String actualQuery1 = controller.createDynamicQuery(selectClaseFields,contact);
}
}
Please let me know if you have any workaround for this issue.
If we down the API version from 30.0 the test class will not throw any error, but when I upload the class from package org it uploaded to APP Exhange and the components run on latest salesforce api version (30.0).
Root cause of the issue-The Type cast issue is related with native fields with Address (otheraddress,mailingaddress,billingaddress) data type. Currently I have not included address type fields to the method and able to solve the issue.
Class:Base_AC_Utility
public String createDynamicQuery2(Set<String> selectClaseFields, SObject sObjectRecord)
{
if(objectName != null && objectName != '' && selectClaseFields != null && selectClaseFields.size() > 0)
{
//get operator for fields which have value in sObject
//Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
Map<String,Schema.SObjectField> M = r.fields.getMap();
Map<String,DisplayType> fieldMap = new Map<String,DisplayType>();
Map<String , Base_Enum_CVMOpearatorsType> fieldWithOperator = new Map<String , Base_Enum_CVMOpearatorsType>() ;
Set<String> existingFieldNamesList = M.keySet();
existingFieldNamesList.remove('otheraddress'); //added this statement to overcome the issue
existingFieldNamesList.remove('mailingaddress');//added this statement to overcome the issue
}
As per my observations the upload package components from package org run always on latest salesforce API version (30.0).
As per the analysis the issue seems to be platform level update in API version 30.0 on Data type conversion and previous versions the existing code working fine.
All Answers
That being said i think the issue if you need to cast the result of .get(fieldname) so
sObjectRecord.get(fieldname)!='[]'
should be
(string) sObjectRecord.get(fieldname)!='[]'
If we down the API version from 30.0 the test class will not throw any error, but when I upload the class from package org it uploaded to APP Exhange and the components run on latest salesforce api version (30.0).
Root cause of the issue-The Type cast issue is related with native fields with Address (otheraddress,mailingaddress,billingaddress) data type. Currently I have not included address type fields to the method and able to solve the issue.
Class:Base_AC_Utility
public String createDynamicQuery2(Set<String> selectClaseFields, SObject sObjectRecord)
{
if(objectName != null && objectName != '' && selectClaseFields != null && selectClaseFields.size() > 0)
{
//get operator for fields which have value in sObject
//Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
Map<String,Schema.SObjectField> M = r.fields.getMap();
Map<String,DisplayType> fieldMap = new Map<String,DisplayType>();
Map<String , Base_Enum_CVMOpearatorsType> fieldWithOperator = new Map<String , Base_Enum_CVMOpearatorsType>() ;
Set<String> existingFieldNamesList = M.keySet();
existingFieldNamesList.remove('otheraddress'); //added this statement to overcome the issue
existingFieldNamesList.remove('mailingaddress');//added this statement to overcome the issue
}
As per my observations the upload package components from package org run always on latest salesforce API version (30.0).
As per the analysis the issue seems to be platform level update in API version 30.0 on Data type conversion and previous versions the existing code working fine.