Skip to content

Instantly share code, notes, and snippets.

@rupton
Last active December 17, 2015 19:59
Show Gist options
  • Save rupton/5664434 to your computer and use it in GitHub Desktop.
Save rupton/5664434 to your computer and use it in GitHub Desktop.
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