Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Can we use describeSObject to get the fields from a Person Account?

Normally we would use the following to get the fields from an Object:

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
Map<String, Schema.SObjectField> fieldMap = schemaMap.get('Account').getDescribe().fields.getMap();

How can we distinguish Person Account Fields from Business Account Fields?

share|improve this question
add comment

2 Answers 2

//To get a map of all fields an object
Map<String, Schema.SObjectField> M =Schema.SObjectType.Account.fields.getMap();
 //Boolean flag to detect person account enabled or not
  Boolean isPersonAccountEnabled=M.containsKey('IsPersonAccount');
  //Debug Statements
   System.debug('MAP DEBUG'+M);
  System.debug('PERSON ACCOUNT ENABLED'+isPersonAccountEnabled);

You are on target.If person Account enabled you will be able to get all fields also the isPersonAccount will be true .

Person Account fields ends with __pc while normal Account fields ends in __c.

share|improve this answer
    
Just added a follow-up question on how we can distinguish Business Account fields and Person Account fields –  Joey Chan Feb 14 '13 at 16:59
    
updated the answer buddy! –  Mohith Shrivastava Feb 14 '13 at 17:23
add comment

You can definitely get Person Account fields using Apex. The following describe of Accounts in my sandbox showed Person Account fields such as PersonHomePhone.

Schema.DescribeSObjectResult a = Account.SObjectType.getDescribe();
Map<String,Schema.SObjectField> accountFields = a.fields.getMap();
for (String key: accountFields.keySet()){
    System.debug(key);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.