You need to sign in to do that
Don't have an account?
Charles McDowell
I am new to Apex. I have the following markup for a new account. I need to add a contact record based on the firstname and lastname inputText fields.Can anyone give me some direction. Thanks
<apex:page standardController="Account">
<apex:pageBlock >
<apex:form >
<apex:pageBlockSection >
<apex:pageBlockSection columns="1">
<apex:commandButton action="{! Save}" value="Save"/>
<apex:inputField value="{! Account.Name}"/>
<apex:inputText id="cFirstName" label="FirstName" />
<apex:inputText id="cLastName" label="LastName" />
<apex:inputField value="{! Account.BillingStreet}"/>
<apex:inputField value="{! Account.BillingCity}"/>
<apex:inputField value="{! Account.BillingState}"/>
<apex:inputField value="{! Account.Phone}"/>
<apex:inputField value="{! Account.BillingStreet}"/>
</apex:pageBlockSection>
</apex:pageBlockSection>
<apex:pageBlock title="Contacts">
<apex:pageBlockSection >
<apex:pageBlockSection columns="2">
</apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:pageBlock>
</apex:page>
<apex:pageBlock >
<apex:form >
<apex:pageBlockSection >
<apex:pageBlockSection columns="1">
<apex:commandButton action="{! Save}" value="Save"/>
<apex:inputField value="{! Account.Name}"/>
<apex:inputText id="cFirstName" label="FirstName" />
<apex:inputText id="cLastName" label="LastName" />
<apex:inputField value="{! Account.BillingStreet}"/>
<apex:inputField value="{! Account.BillingCity}"/>
<apex:inputField value="{! Account.BillingState}"/>
<apex:inputField value="{! Account.Phone}"/>
<apex:inputField value="{! Account.BillingStreet}"/>
</apex:pageBlockSection>
</apex:pageBlockSection>
<apex:pageBlock title="Contacts">
<apex:pageBlockSection >
<apex:pageBlockSection columns="2">
</apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:pageBlock>
</apex:page>
You will need to add an controller or extension to save both account and contact from same page. You can try the below code that utilzes an custom controller.
Your Controller will be Please add / remove fields that you dont need. Hope this helps