You need to sign in to do that
Don't have an account?
vishal yadav 86
My requirement is to show account block first and after account record inserted show contact block
VF PAGE CODE :
<apex:page controller="InsertAcc_Con" sidebar="False" tabstyle="Campaign">
<apex:sectionHeader title="Main Section" subtitle="Recrd Insertion"/>
<apex:form >
<apex:PageBlock title="Record Insert Block">
<apex:PageblockSection title="New Account Section" id="Accblock">
<apex:inputText label="Name" value="{!Nval}"/>
<apex:inputText label="Phone" value="{!Pval}"/>
<apex:inputText label="Website" value="{!Wval}"/>
<apex:commandButton value="Insert" action="{!InsertAccount}" rerender="Accblock"/>
</apex:PageblockSection>
<apex:PageblockSection title="New Contact Section" id="ConBlock">
<apex:inputText label="First Name" value="{!Fval}"/>
<apex:inputText label="Last Name" value="{!Lval}"/>
<apex:inputText label="Phone" value="{!CPval}"/>
<apex:inputText label="Fax" value="{!CFval}"/>
<apex:commandButton value="Insert" action="{!InsertContact}" rerender="ConBlock"/>
</apex:PageblockSection>
</apex:PageBlock>
</apex:form>
</apex:page>
VF CONTROLLER CLASS :
public class InsertAcc_Con
{
public string Nval{get;set;}
public string Pval{get;set;}
public string Wval{get;set;}
public void InsertAccount()
{
account acc = new account();
acc.name = Nval;
acc.phone = Pval;
acc.website = Wval;
insert acc;
}
public string Fval{get;set;}
public string Lval{get;set;}
public string CPval{get;set;}
public string CFval{get;set;}
Public void InsertContact()
{
contact con = new contact();
con.firstname = Fval;
con.lastname = Lval;
con.phone = CPval;
con.fax= CFval;
insert con;
}
<apex:page controller="InsertAcc_Con" sidebar="False" tabstyle="Campaign">
<apex:sectionHeader title="Main Section" subtitle="Recrd Insertion"/>
<apex:form >
<apex:PageBlock title="Record Insert Block">
<apex:PageblockSection title="New Account Section" id="Accblock">
<apex:inputText label="Name" value="{!Nval}"/>
<apex:inputText label="Phone" value="{!Pval}"/>
<apex:inputText label="Website" value="{!Wval}"/>
<apex:commandButton value="Insert" action="{!InsertAccount}" rerender="Accblock"/>
</apex:PageblockSection>
<apex:PageblockSection title="New Contact Section" id="ConBlock">
<apex:inputText label="First Name" value="{!Fval}"/>
<apex:inputText label="Last Name" value="{!Lval}"/>
<apex:inputText label="Phone" value="{!CPval}"/>
<apex:inputText label="Fax" value="{!CFval}"/>
<apex:commandButton value="Insert" action="{!InsertContact}" rerender="ConBlock"/>
</apex:PageblockSection>
</apex:PageBlock>
</apex:form>
</apex:page>
VF CONTROLLER CLASS :
public class InsertAcc_Con
{
public string Nval{get;set;}
public string Pval{get;set;}
public string Wval{get;set;}
public void InsertAccount()
{
account acc = new account();
acc.name = Nval;
acc.phone = Pval;
acc.website = Wval;
insert acc;
}
public string Fval{get;set;}
public string Lval{get;set;}
public string CPval{get;set;}
public string CFval{get;set;}
Public void InsertContact()
{
contact con = new contact();
con.firstname = Fval;
con.lastname = Lval;
con.phone = CPval;
con.fax= CFval;
insert con;
}
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
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
I have made changes in your code.Try this one.
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards