Showing posts with label instanceof. Show all posts
Showing posts with label instanceof. Show all posts

Tuesday, March 19, 2013

Apex, check object by Id. Ver 3.0

This is new version of method that I mentioned in my previous topics: 'Apex, check object by Id' and 'Apex, check object by Id. Update.'. Earlier, if Id.valueOf( objectIdString ) == null we had an error 'FATAL_ERROR System.StringException: Invalid id'. To avoid this error I use 'instanceof'. So now will not have any errors, even if we do not have such object in system like 'objectTypeNameString' or it will be null.
public static Boolean isIdsObjectTypeEqualToStringObjectType( String objectIdString, 
                 String objectTypeNameString ){
 
 return ( ( objectIdString instanceof Id )  
             && Id.valueOf( objectIdString ).getSObjectType().getDescribe().getName().equals( objectTypeNameString ) );
}
Test class will be the same.

Enjoy.