Last active
December 17, 2015 19:59
-
-
Save rupton/5664434 to your computer and use it in GitHub Desktop.
Object Type Comparison Using Ajax with Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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