You need to sign in to do that
Don't have an account?
chidambarakumari r
Binding two standard object using VF page
Hi,
I'm trying to bind two standard objects using VF page but I'm getting an error "Variable AccountID not exist"
public class AccountController {
public Contact newContact{get;set;}
public Account newAccount{get;set;}
public AccountController (ApexPages.StandardController controller) {
newContact = new Contact();
newAccount = new Account();
}
public pagereference dosave()
{
insert newAccount;
newcontact.Accountid=newAccount.id;
PageReference acc = new ApexPages.StandardController(newAccount).view();
acc.setRedirect(true);
return acc;
}
}
****************************
<apex:page standardController="contact" extensions="AccountController">
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:inputField value="{!newContact.Lastname}"/>
<apex:inputField value="{!newAccount.Name}"/>
<apex:commandButton action="{!dosave}" value="Save"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I'm trying to bind two standard objects using VF page but I'm getting an error "Variable AccountID not exist"
public class AccountController {
public Contact newContact{get;set;}
public Account newAccount{get;set;}
public AccountController (ApexPages.StandardController controller) {
newContact = new Contact();
newAccount = new Account();
}
public pagereference dosave()
{
insert newAccount;
newcontact.Accountid=newAccount.id;
PageReference acc = new ApexPages.StandardController(newAccount).view();
acc.setRedirect(true);
return acc;
}
}
****************************
<apex:page standardController="contact" extensions="AccountController">
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:inputField value="{!newContact.Lastname}"/>
<apex:inputField value="{!newAccount.Name}"/>
<apex:commandButton action="{!dosave}" value="Save"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
please try this piece of code. Hope it will help you.
Page :
Controller :
If this code helps you.Please mark it as best.
- You want to automatically create a new child record when you create a parent record.
- http://developer.force.com/cookbook/recipe/creating-a-child-record-when-a-parent-record-is-created
Hope it helps.Thanks
Rahul Kumar
Still I'm getting the error Error: Compile Error: Variable does not exist: Accountid at line 14 column 12