+ Start a Discussion
azhar khasimazhar khasim 

Record type need to be inserted in Visualforce page i have inserted it but getting so many errors



<apex:page standardController="Account" >
    <apex:form>
        <apex:sectionHeader title="Person Customer Edit" subtitle="New Customer"/>
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="cancel"/>
                </apex:pageBlockButtons>
            </apex:pageBlock>
        <apex:pageBlock>
<apex:pageBlockSection>
    <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:pageBlockSection>
            </apex:pageBlock>
    <apex:pageBlock>
        <apex:pageBlockSection>
<apex:pageBlockSectionItem>
<apex:outputLabel value="Last Name" for="personLname"></apex:outputLabel>
<apex:inputText value="{!lname}" id="personLname"/>
</apex:pageBlockSectionItem>
           </apex:pageBlockSection> 
            </apex:pageBlock>
    </apex:form>
</apex:page>

this is my code which i was unable to do.
My Error: Unknown property 'AccountStandardController.salutation'
MKRMKR
Hi,

Try to use {!account.salution} instead of {!salutation} in all expressions.

Regards,
MKR
azhar khasimazhar khasim
Hi MKR,

While I have got some other error like
'Invalid field fname(firstName)for SObject Account'


In the Account Object, we have another one like Person Account 
Actually, We have Salutation, firstName,lastName is in Person Account which has separate Record Type
So we need to get those data in it.
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Azhar,

Greetings to you!

Below is the sample code. Kindly modify the code as per your requirement.
<apex:page standardController="Account" tabStyle="Account">
    <apex:form>
        <apex:sectionHeader title="Person Customer Edit" subtitle="New Customer"/>
        <apex:pageBlock > 
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="cancel"/>
            </apex:pageBlockButtons>
            <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>
        </apex:pageBlock>
    </apex:form>
</apex:page>

If you want to create person account using custom controller then use below code.

Visualforce:
<apex:page controller="CreatePersonAcc">
    <apex:form>
        <apex:sectionHeader title="Person Customer Edit" subtitle="New Customer"/>
        <apex:pageBlock > 
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection>
                <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>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class CreatePersonAcc {
    
    Account acct; 
    public String salutation {get; set;}
    public String fname{get; set;}
    public String lname{get; set;}
    
    public CreatePersonAcc(){
        acct = new Account();
    }
    
    public PageReference save() {
        try {
            // check for person account record type
            RecordType 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;
        }  
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
MKRMKR
Hi,

Try {!account.PersonSalutation}.

Regards,
MKR