2

I have recently activated and configured Person Accounts in our salesforce org. We will be using these within the service console and also integrating Postcode Anywhere for address lookups. To integrate PA in the console, it has to be done via a visualforce page as there is no sidebar to load the app. To resolve this, I have created a Visualforce page that covers all account record types, including Person Accounts and have overridden the 'new' and 'edit' buttons to call the VF page.

So far so good. Now, when editing accounts, everything works currently, all fields show and PA works fine. BUT, when creating a NEW Person Account, the Salutation, First Name and Last Name field so not show on the page and so the record cannot be saved (as Last Name is required to create an account).

Having spoken to Salesforce about this (as this is quite a fundamental issue), they claim the those 3 fields have no API field definitions and so cannot be called via a VF page. That's obviously no correct as they work fine in edit mode (having created a person account using the standard page) and they are also listed in the WSDL file.

Having Google'd a LOT, I believe the problem is there because the isPersonAccount boolean field is not set at the point of creating the account (in VF) and therefore the page does not allow the name fields to render.

So on to my question (I've not had much experience with VF or controllers), is it possible to somehow set the isPersonAccount field to true using a controller extension or something similar, when creating a person account via VF. Or can the page be somehow saved before presenting it to the user so the field gets set and the name fields then render?

Any help with this would be massively appreciated as Salesforce aren't being exactly helpful and I can't be the only person in the world that needs to create a person account via a visualforce page?

  • Is person Account is read only field in sfdc.It cannot be updated – Mohith Shrivastava Jul 30 '13 at 10:23
  • Well, considering that the standard SF UI allows you to create new Person Accounts it can obviously be done. Are you using the standard Account controller? – Mike Chale Jul 30 '13 at 11:25
  • Yes it's using the standard controller, and this is my point. Salesforce told me that the fields cannot be used on the VF page, which tells me it's impossible to create a person account via VF. That's obviously not true and I think they fobbed me off as they didn't know how to resolve it, but something isn't right if the fields are not showing on a new record. – Steve Mason Jul 30 '13 at 11:59
4

Resolved as follows:

Controller code (partial):

Account acct; 
public String salutation {get; set;}
public String fname{get; set;}
public String lname{get; set;}

public PageReference save() {
    try {
        // check for person account record type
        recType = [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];
        if(acct.recordtypeid == recType.id) {
            acct.Salutation=salutation;
            acct.FirstName=fname;
            acct.LastName=lname;
            insert(acct);                    
            PageReference newPage = New PageReference('/'+acct.id);
            newPage.setRedirect(true);
            return newPage;
        }
        else {
            insert(acct);    
            PageReference newPage = New PageReference('/'+acct.id);
            newPage.setRedirect(true);
            return newPage;
        }
    }
    catch(System.DMLException e) {
            ApexPages.addMessages(e);
             return null;
    }  
    return null;
}

Visualforce code (partial):

<apex:pageblocksectionitem >
    <apex:outputlabel value="First Name"/>
    <apex:outputpanel >
        <apex:inputText value="{!salutation}" id="personSalutation"/>
        <apex:inputText value="{!fname}" id="personFname"/>
     </apex:outputpanel>
</apex:pageblocksectionitem>
<apex:pageBlockSectionItem>
    <apex:outputLabel value="Last Name" for="personLname"></apex:outputLabel>
    <apex:inputText value="{!lname}" id="personLname"/>
</apex:pageBlockSectionItem>
|improve this answer|||||
  • Good job figuring that out! – Mike Chale Aug 1 '13 at 11:33
0

Process Builder uses Account.PersonContact to bridge Account and Contact fields. This works in Visualforce to create a new Person Account without need of a custom controller:

Visualforce (partial):

    <apex:page standardController="Account" tabStyle="Account">
    ...
    <apex:pageBlock id="pgBlock" mode="edit" title="Person Account Edit"> 
    <apex:pageBlockSection id="AcctInfo" title="Account Information" columns="2" >
        <apex:pageBlockSectionItem >
            <apex:outputLabel >First Name</apex:outputLabel>
            <apex:pageBlockSectionItem>
                <apex:inputField id="Salutation" value="{!account.PersonContact.Salutation}" />
                <apex:inputField id="FirstName" value="{!account.PersonContact.FirstName}" style="width: 100px;" />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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