I am writing a code where I have to create an AccountTeamMember Record if the AccountTeamMember object exists on Org. To check the existence of AccountTeamMember object I have used the following code :
public static Boolean checkObjectExistance (String objectName) {
Boolean objectExist = false ;
Map<String, Schema.SObjectType> objectMap = Schema.getGlobalDescribe();
if(objectMap.get(objectName)!=null){
objectExist=true;
}
return objectExist;
}
Now using its Return value and IF condition, I have to create AccountTeamMember Record :
e.g
If(FetchMetadata.checkObjectExistance('AccountTeamMember') == true){
AccountTeamMember testAccTeamMember = new AccountTeamMember();
testAccTeamMember.AccountId=//SomeAcountId;
testAccTeamMember.UserId=//someId;
Insert testAccTeamMember;
}
But,I can not save the code because the AccountTeamMember currently does not exist in ORG. Is there any way which will allow me to save this code so that it can work on any org which does not have AccountTeamMember object and also on the org which has AccountTeamMember ?