function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
najnaj 

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. 

 

Best Answer chosen by Admin (Salesforce Developers) 
imutsavimutsav
fName, lName, email are just the example of the field names you have on your custom object. Name is one of the required field you should have on custom object. You need to replace all the other fields with the name of the fields you have on your custom object. Or just to test this you should comment the lname and email code
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

imutsavimutsav

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. ;) ]

 

 

najnaj

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

imutsavimutsav
Change
<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. ;) ]

najnaj

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? 

imutsavimutsav
No you don't have to change the name of the VF page. You can call it what ever you want. Oh I see in the code, my mistake change broker_c to broker__c or what ever is the name of your Object. You need to make this change every where in the code.

Thanks
Utsav

[do mark it as a solution or give kudos if you think i helped you any bit. ;) ]

najnaj

I made that change already but the it is unable to identify string.fname

imutsavimutsav
fName, lName, email are just the example of the field names you have on your custom object. Name is one of the required field you should have on custom object. You need to replace all the other fields with the name of the fields you have on your custom object. Or just to test this you should comment the lname and email code
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 was selected as the best answer
AkiloveAkilove

This is apex code

<apex:page standardController="Invoice_Statement__c" extensions="myControllerTest">
<apex:messages />
        <apex:form >
        <apex:pageBlock >
        <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!submit}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection >         
        <apex:inputField required="true" value="{!Invoice_Statement__c.Description__c}"/>
        <apex:inputField required="true" value="{!Invoice_Statement__c.Status__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

 This is myControllerTest code

public with sharing class myControllerTest {
    public Invoice_Statement__c invoice{get;set;}

    public myControllerTest(ApexPages.StandardController controller) {
        invoice = new Invoice_Statement__c();
    }
    
    public void submit() {
        try {
            if(Invoice_Statement__c.Description__c!=NULL) {
                insert invoice;
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Infomation Saved successfully')); 
            } else {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please Enter')); 
            }
        } catch(Exception e) {
        System.debug('-----Exception -----' + e);
        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'System Error : Contact System Admin')); 
     }

}

 Why run error :

Error: myControllerTest Compile Error: expecting right curly bracket, found 'EOF' at line 0 column -1

Can help me!!!!!

nimznimz
You have missed out on a curly brace at the end.