You need to sign in to do that
Don't have an account?
Displaying Custom Object Fields in Class
Hi SF Community!
I am not a Dev. I am an Administrator. Wanted to get that out of the way, first and foremost ;) However, I wan to learn basic visualforce code so I can add elements to my SF org. I've dabbled in existing code within our org, and have been an Admin long enough to understand how most of it all works.
I've created a simple custom object called Check List. I have a few custom fields within it. I'm going to embed a VF page within the page layout, and that's where I was hoping someone could help me out?
I've used the sample controller and VF page code from this post: https://developer.salesforce.com/forums/?id=906F000000009epIAA
I want to modify it so I can include custom fields other than Name and id (per the sample in the above link).
The custom fields I want to include are:
- Assigned To (LookupUser)
- Item (Long Text Area)
- Completed (checkbox)
If anyone can help me figure out how to put these fields in this sample VF page code, that would be super helpful:
<apex:page Controller="customController">
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:pageBlockTable Id="allcon" value="{!objlist}" var="ans" rendered="{!If(objlist != null,True,False)}" width="100%">
<apex:column ><apex:facet name="header">id</apex:facet>
<apex:outputfield value="{!ans.id}"></apex:outputfield>
</apex:column>
<apex:column > <apex:facet name="header">Name</apex:facet>
<apex:outputLink Value="/{!ans.Id}">
<apex:outputfield value="{!ans.Name}"></apex:outputfield></apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form >
</apex:page>
Thanks much!
Nick
Hey,
Update the custom controller to fetch the required fields that you want.
Then simply on your VF page add them as apex:outputfield. ThanksThanks, Tejender!
Seeing the result, this isn't what I need...hahaha. This is just displaying field data. I want it to be a editable form that displays these fields (Assigned To, Item, Completed). Is there any simple code samples for such an ask?
You can use inputField instead of outputField for that.
cuslist = [Select Id,AssignedTo,Item,Completed from YourCustomObject];
<apex:page StandardController="CustomObjectName__c">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection >
<apex:repeat value="{!conList}" var="co">
<apex:inputField value="{!co.AssignedTo}" label="AssignedTo"/>
<apex:inputField value="{!co.Item}" label="Item"/>
<apex:inputField value="{!co.Completed}" label="Completed"/>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex>
Please let me know if you have any queries.
Thanks,
Sowmya.
Please try this code:-
Apex class :
Please mark as best answer if it helps you.
Thank You
Ajay Dubedi
Thanks for the options, everyone!
Looks like I just had to replace my outputfield with inputfield.
My next part of this equation is to use the CommandButton tag and addrow action. Essentially, I want there to be a button called 'Add New' on this page that will allow a user to click this button and the fields in my above noted code will show up with blank values so users can add values to these fields. Can anyone help me with this portion of code?
Please refer the below code:
VF Page:
<apex:page standardController="Account" extensions="AddRowsAction" >
<apex:form >
<apex:pageBlock id="accAdd" >
<apex:pageblockSection >
<apex:pageBlockTable value="{!accAddList}" var="a">
<apex:column headerValue="Account Name">
<apex:inputField value="{!a.Name}" />
</apex:column>
<apex:column headerValue="Mobile Number">
<apex:inputField value="{!a.phone}"/>
</apex:column>
</apex:pageBlockTable>
<br/><apex:commandLink value="Add Row" action="{!addRow}" reRender="accAdd"/>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class AddRowsAction {
// public List<Account> accList {get;set;}
public List<Account> accAddList {get;set;}
public String accName {get;set;}
public AddRowsAction(ApexPages.StandardController controller)
{
// accList=[select id,name,phone from Account];
accAddList = new List<Account>();
accAddList.add(new Account());
}
public void AddRow()
{
accAddList.add(new Account());
}
}
Thanks,
Sowmya