Skip to content

Instantly share code, notes, and snippets.

@rupton
Last active December 17, 2015 19:59
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Object Type Comparison Using Ajax with Test
public class ObjectHelper{
public static boolean compare(SObject compare, String checkType){
try{
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(checkType);
if(targetType == null){
return false;
}else if( compare.getSObjectType() == targetType){
return true;
}else{
return false;
}
}catch(Exception e){
//handle exception
return false;
}
return false;
}
}
TEST:
Project__c project = [select id, ownerId from project__c][0];
Schema.SObjectType oType = project.ownerId.getSObjectType();
SObject myObj = oType.newSObject(project.ownerId);
If( ObjectHelper.isType(myObj, 'User')){
//do something with the User
} else {
//do something with Group
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment