code to create a view poage in visualforce
- User
code to create a view poage in visualforce
- Assistant
Here is an example code to create a view page in Visualforce:
<apex:page standardController="Account" recordSetVar="accounts">
<apex:pageBlock title="Accounts">
<apex:pageBlockTable value="{!accounts}" var="acc"> <apex:column value="{!acc.Name}"/> <apex:column value="{!acc.Phone}"/> <apex:column value="{!acc.Website}"/> </apex:pageBlockTable></apex:pageBlock>
</apex:page>
This code creates a Visualforce page that displays a table of accounts and their associated data. The page uses the standardController and recordSetVar attributes to retrieve a list of accounts and display them in a pageBlockTable. The pageBlockTable includes columns for the account name, phone number, and website URL.
- User
code to create student view page in visualforce
- Assistant
Here is an example code to create a student view page in Visualforce:
<apex:page standardController="Student__c" recordSetVar="students">
<apex:pageBlock title="Students">
<apex:pageBlockTable value="{!students}" var="stu"> <apex:column value="{!stu.Name}"/> <apex:column value="{!stu.Roll_Number__c}"/> <apex:column value="{!stu.Marks__c}"/> </apex:pageBlockTable></apex:pageBlock>
</apex:page>
In this code, we are using a custom object "Student__c" which has three fields: Name, Roll_Number__c, and Marks__c. We have used the standardController attribute to retrieve the data from this object and display it in a pageBlockTable. The pageBlockTable includes columns for the student's name, roll number, and marks. The records of the object are retrieved using the recordSetVar attribute.
- User
<apex:page controller="FirstController">
<apex:form> <apex:pageBlock title="Account,Contact and Opportunity Create page"> <apex:pageBlockSection title="Account information"> <apex:inputText value="{!accName}" label="Account Name" /> <apex:inputText value="{!accEmployees}" label="Number of Employees" /> </apex:pageBlockSection> <apex:pageBlockSection title="Contact information"> <apex:inputText value="{!conName}" label="Contact Name" /> <apex:inputText value="{!conEmployees}" label="Email of Contacts" /> </apex:pageBlockSection> <apex:pageBlockSection title="opportunity information"> <apex:inputText value="{!oppName}" label="Name of the opportunity" /> <apex:inputText value="{!oppEmployees}" label="Amount of the opportunity" /> </apex:pageBlockSection> <apex:commandButton value="{!saveTheRecord}" title="saveTheRecord"/> </apex:pageBlock> </apex:form></apex:page>
- Assistant
This is an example code for an Apex controller and Visualforce page that creates a page for creating Account, Contact, and Opportunity records. The page includes input fields for all required fields for these objects and a Save button that will save the entered data to the respective objects.
The Apex controller for this page might look something like this:
public class FirstController {
public String accName {get; set;} public Integer accEmployees {get; set;} public String conName {get; set;} public String conEmail {get; set;} public String oppName {get; set;} public Integer oppAmount {get; set;} public void saveTheRecord() { Account newAccount = new Account(); newAccount.Name = accName; newAccount.NumberOfEmployees = accEmployees; insert newAccount; Contact newContact = new Contact(); newContact.FirstName = conName; newContact.Email = conEmail; insert newContact; Opportunity newOpportunity = new Opportunity(); newOpportunity.Name = oppName; newOpportunity.Amount = oppAmount; insert newOpportunity; } - User
What is the error in the fallowing codepublic class FirstController {
public String accName; public Integer accEmployees{get;set;} public String conName{get;set;} public String conEmail{get;set;} public String oppName{get;set;} public Decimal oppAmount{get;set;} public FirstController() { } public void saveTheRecord(){ Account a = new Account(Name = accName,NumberOfEmployees = accEmployees); insert a; Contact c = new Contact(LastName = conName, email = conEmail, accountid = a.id); insert c; Opportunity o = new Opportunity(Name = oppName, Amount = oppAmount, accountid = a.id); insert o; } public void setAccName(String a){ accName = a; } public String getAccName(){ return accname; }}
- Assistant
The error in the code is in the getter method of the accName variable. In the getAccName() method, the variable name is spelled incorrectly. Instead of
accname, it should be spelled with a capital "N" asaccName, which matches the variable name defined at the top of the controller. This is causing a variable reference error when the method is called.To fix this, simply update the getAccName() method to return the value of the
accNamevariable with the correct spelling:public String getAccName(){ return accName; }With this correction, the code should compile and execute successfully.
- User
Unknown property 'FirstController.saveTheRecord'
- Assistant
The error "Unknown property 'FirstController.saveTheRecord'" indicates that there is no property or method called "saveTheRecord" defined in the FirstController class.
This error can occur if there is a typo in the method name, or if the method has not been defined in the controller at all.
To fix the error, make sure that the method is spelled correctly and that it is defined properly in the controller. Double-check that the method name is exactly the same in the Visualforce page and the Apex controller.
In the case of this specific code, make sure that the
saveTheRecordmethod is defined within theFirstControllerclass and that it has the correct method signature. The method should not have any input parameters and should have a "void" return type.Example of a correctly defined
saveTheRecordmethod:public void saveTheRecord() { // code to save the record goes here }Make sure that the method is included in the Visualforce page's apex:commandButton component, using the correct syntax, for example:
<apex:commandButton value="Save" action="{!saveTheRecord}"/>With these corrections made, the error "Unknown property 'FirstController.saveTheRecord'" should be resolved.