You need to sign in to do that
Don't have an account?
integrate visualforce page to custom object
Hi
I have a custom object named broker_c. We developed a visualforce page asking for the customers first name, last name , phone number and email id. Once the customers clicks on submit in the visualforce page link, all the details must be imported into the 'broker_c' custom object. This can be done by web-to-lead form, but these customers are that the leads for my company.
So please let me know the solution to integrate the visualforce page details into the custom object. i figured out that the custom object 'broker_c' is going to be the standard controller in the visualforce page. But what would be the next step?
Please help me with coding.
eg.
Change this code
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name" for="fName" />
<apex:inputText value="{!control.fName}" id="fName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Last Name" for="lName"/>
<apex:inputText value="{!control.lName}" id="lName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Email" for="email"/>
<apex:inputText value="{!control.email}" id="email"/>
</apex:pageBlockSectionItem
to
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name" for="fName" />
<apex:inputText value="{!control.Name}" id="fName"/>
</apex:pageBlockSectionItem>
Thanks
Utsav
[do mark it as a solution or give kudos if you think i helped you any bit. ;) ]
....
All Answers
Try this :
<apex:page controller="myController" tabStyle="broker_c" title="Form" sidebar="true" expires="600">
<html>
<body>
<apex:form >
<apex:pageBlock title="My Test page" id="entireForm" mode="edit">
<apex:pageMessages id="msg"/>
<apex:pageBlockButtons id="buttons">
<apex:commandButton status="pStatus" action="{!submit}" value="Submit" rerender="msg"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Form" columns="2" id="pbSection">
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name" for="fName" />
<apex:inputText value="{!control.fName}" id="fName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Last Name" for="lName"/>
<apex:inputText value="{!control.lName}" id="lName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Email" for="email"/>
<apex:inputText value="{!control.email}" id="email"/>
</apex:pageBlockSectionItem></apex:pageBlockSection> </apex:pageBlock> </apex:form> </body> </html> </apex:page>
public with sharing class myController {
public broker_c control{get;set;}
public myController() {
control = new broker__c();
}
public void submit() {
try {
if(control.Name!=NULL) {
insert control;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Infomation Saved successfully'));
} else {
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please Enter the First Name'));
}
} catch(Exception e) {
System.debug('-----Exception -----' + e);
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'System Error : Contact System Admin'));
}
}
Thanks
Utsav
Thanks
[do mark it as a solution or give kudos if you think i helped you any bit. ;) ]
Hi Utsav,
Thank you for the code.
But when tried the code that you gave me in visualforce page and apex class as mycontroller. apex class i created for it is public sharing class.
The below error is popping up.
Error: myController Compile Error: expecting right curly bracket, found 'EOF' at line 0 column -1
Let me know how to fix it.
Thanks
Jyothi
<apex:page controller="myController" tabStyle="broker_c" title="Form" sidebar="true" expires="600">
to
<apex:page standardController="broker_c" extensions="myController" tabStyle="broker_c" title="Form" sidebar="true" expires="600">
Add one more constructor to the controller.
public myController(ApexPages.StandardController con) {
control = new broker__c();
}
Did you save the Controller with the same name as the controller class.
Eg. myController
If theis doesn't help then copy and paste your entire code.
Thanks
Utsav
[do mark it as a solution or give kudos if you think i helped you any bit. ;) ]
Hi Utsav,
I did the changes. Now its saying broker_c does not exist.
Regarding the visualforce page name, it is different from the mycontroller.
Should it be same?
do i need to change the vf input and output name according to custom object fields api's?
Thanks
Utsav
[do mark it as a solution or give kudos if you think i helped you any bit. ;) ]
I made that change already but the it is unable to identify string.fname
eg.
Change this code
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name" for="fName" />
<apex:inputText value="{!control.fName}" id="fName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Last Name" for="lName"/>
<apex:inputText value="{!control.lName}" id="lName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Email" for="email"/>
<apex:inputText value="{!control.email}" id="email"/>
</apex:pageBlockSectionItem
to
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name" for="fName" />
<apex:inputText value="{!control.Name}" id="fName"/>
</apex:pageBlockSectionItem>
Thanks
Utsav
[do mark it as a solution or give kudos if you think i helped you any bit. ;) ]
....
This is apex code
This is myControllerTest code
Why run error :
Error: myControllerTest Compile Error: expecting right curly bracket, found 'EOF' at line 0 column -1
Can help me!!!!!