I have a field set on a Visual Force Page. I want to customize the field labels displayed to the user.
Currently, my custom contact field is birthdate, but it'd be better Date of Birth.
Here is the code:
<apex:pageBlockSection title="Candidate Information">
<apex:repeat value="{!$ObjectType.Contact.FieldSets.contactForm}"
var="c">
<apex:inputField value="{!Contact[c]}" />
</apex:repeat>
</apex:pageBlockSection>
It outputs like:
Birthdate [ input field ]
Should be:
Date of Birth [ input field ]
Any idea how I can customize the output label?
Thanks.
You can do this:
<apex:inputField value="{!Contact[c]}" label="{!IF(c.label== 'Birthdate','Date of birth',c.label)}" />
Related
I am newbie at visualforce and i have a few questions. I was able to create a basic visualforce page:
<apex:page standardController="Campaign">
<apex:sectionHeader title="Campaign" subtitle="Campaign Edit"/>
<apex:form id="theForm">
<apex:pageBlock title="Campaign" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton value="Save & New" action="{!'save & new'}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:inputText value="{!Campaign.name}" id="name"/>
<apex:inputfield value="{!Campaign.Campaign_Type__c}">
<apex:actionSupport event="onchange" reRender="theForm" />
</apex:inputField>
<apex:inputtext value="{!Campaign.PPC__c}" rendered="{!Campaign.Campaign_Type__c == 'Campaign Type 1'}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
https://ibb.co/iWSVVS
The field "Campaign name" is a required field how can i add the red bar next to the field?
How can I "combine" several fields together and insert them as a value to the field Campaign name? for example i have a dropdown field "Campaign_Type__c=Type 1" and i also have a text box field "Campaign_textbox1__c=alex" I want to combine them as "Type 1 alex" and set this as a value for the field name "Campaign name".
Thank you
For the required just set the attribute to the tag:
<apex:inputText value="{!yourVaue}" id="yourid" required="true" />
Can you not do a formula field for the Campaign name?
One that concatenates the fields together. So create a formula field called Campaign name, then use my formula below:
Campaign Name = Campaign_Type__c & " " & Campaign_textbox1__c
The reason for the space is that otherwise it'll stick it together like "Type 1Alex"
With your other question, i'd just use HTML formatting to get this. Maybe use a pipe? | - one that's bold and red - but i'm lazy
Add the attribute required="true" to make it required i.e. red bar next to the field.
Therefore, you can achieve this by
<apex:inputText value="{!Campaign.name}" id="name" required="true"/>
I have below requirement to Create a VF page – ‘Registration Forum’ having
1.Name field
2.Age field
3.Project Unit field
4.Gender as Radio Button with values – M and F
5.Certification as Picklist with Values – PD1, ADM 201, PD2, App Builder, Sales Cloud, Service Cloud
6.2 buttons – save and reset
7.Attachment area – where we can browse and add any document there.
Save Button – A record should get created in one object (Any object u can mention)
Reset Button – Page should not get refreshed, just values get refreshed with blank value.
As I am new to SFDC, could you please help me to get it done?
Thanks
It's hard to tell from your question exactly what you're looking for, but here is a visualforce page that saves to a custom object called Form__c.
To do the save and reset you'll probably need an Apex extension. I'm not sure if your browse documents is for Salesforce documents or local files.
<apex:page standardController="Form__c" >
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:inputField value="{!Form__c.Name}" />
<apex:inputField value="{!Form__c.Age__c}" />
<apex:inputField value="{!Form__c.Project_Unit__c}" />
<apex:selectRadio value="{!Form__c.Gender__c}" ><apex:selectOption itemValue="Male" itemLabel="Male" /><apex:selectOption itemValue="Female" itemLabel="Female" /></apex:selectRadio>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Hi here is the sample code for your asking for form submission.i have create custom object Registration_Forum__c.
Click to see Custom Object Registration_Forum__c Image
<apex:page Controller="VFFileUpload">
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:form>
<apex:pageBlock title="Upload Attachment">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!saveForm}" />
<apex:commandButton value="reset" action="{!resetForm}" />
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:inputField value="{!Registration_Forum.Name}" />
<apex:inputField value="{!Registration_Forum.age__c}" />
<apex:inputField value="{!Registration_Forum.Certification__c}" />
<apex:inputField value="{!Registration_Forum.Project_Unit__c}" />
<apex:selectRadio value="{!Registration_Forum.Gender__c}">
<apex:selectOption itemValue="Male" itemLabel="Male" />
<apex:selectOption itemValue="Female" itemLabel="Female" />
</apex:selectRadio>
<apex:inputFile id="file" value="{!fileBody}" filename="{!fileName}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class VFFileUpload
{
public Registration_Forum__c Registration_Forum{get;set;}
public String fileName {get;set;}
public Blob fileBody {get;set;}
public VFFileUpload() {
Registration_Forum=new Registration_Forum__c();
}
public void saveForm(){
upsert Registration_Forum;
if(fileBody != null && fileName != null && Registration_Forum.id!=null)
{
Attachment myAttachment = new Attachment();
myAttachment.Body = fileBody;
myAttachment.Name = fileName;
myAttachment.ParentId = Registration_Forum.Id;
upsert myAttachment;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'File Upload Success'));
}
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Form Submission Success'));
}
public void resetForm(){
Registration_Forum=new Registration_Forum__c();
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Reset'));
}
}
I have a VF page where I am using checkbox fiels, I want to display three other fiels if the checkbox is selected.
How can I go about doing that ?
Thanks !!
Use the rendered attribute on <apex:inputfield> or <apex:inputtext>. By setting this attribute, you can control whether or not a component appears on a Visualforce Page.
Include all fields that may or may not be shown on the Visualforce Page, but set rendered="{!Object.YourCheckboxField}" on the fields that you want to show/hide based on the checkbox field. Optionally, you can use a Visualforce function like IF or NOT.
For example, if you wanted to show or hide the Email field on Contacts based on whether or not the HasOptedOutOfEmail field is true or false, it would look like this.
<apex:page standardController="Contact">
<apex:sectionHeader title="Custom Contact Visualforce Page" />
<apex:form>
<apex:pageblock>
<apex:pageblocksection>
<apex:inputfield value="{!Contact.FirstName}" />
<apex:inputfield value="{!Contact.LastName}" />
<apex:inputfield value="{!Contact.Phone}" />
<apex:inputfield value="{!Contact.Email}" rendered="{!NOT(Contact.HasOptedOutOfEmail)}" />
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
I have a VF page where i am using a apex:pageblocktable to display bunch of records.
One of the columns is a picklist and i need to display/not display fields according to selection on the picklist.
<apex:pageBlockTable value="{!showRecord}" var="item">
<apex:column headerValue="Delivery">
<apex:inputField value="{!item.delivery__c}"/>
</apex:column>
<apex:column headerValue="Roadway">
<apex:inputField value="{!item.road__c}"/>
</apex:column>
<apex:column headerValue="Rail">
<apex:inputField value="{!item.rail__c}"/>
</apex:column>
</apex:pageBlockTable>
in the above code delivery_c is picklist with values roadways and railways. if the user selects roadways then i need to display road--c and if user selects railways then i need to display rail_c
How can i go about doing that?
Thanks
One way to do this would be to use partial-page refreshes in Visualforce.
Put both fields in the same column and use the "rendered" attribute to dynamically show/hide the field using an if-statement. Then you set up an AJAX onchange event handler for the delivery__c field using the actionSupport tag. This will basically listen for that field to change then refresh the table on the page. Each time this is refreshed, your if statements will be re-evaluated and result in showing one of the two fields in that column.
I didn't get a chance to try this but I think it should work.
<apex:pageBlockTable id="mytable" value="{!showRecord}" var="item">
<apex:column headerValue="Delivery">
<apex:actionRegion>
<apex:inputField value="{!item.delivery__c}">
<apex:actionSupport event="onchange" reRender="mytable">
</apex:inputField>
</apex:actionRegion>
</apex:column>
<apex:column headerValue="Delivery Type">
<apex:inputField rendered="{!item.delivery__c='Road'}" value="{!item.road__c}"/>
<apex:inputField rendered="{!item.delivery__c='Rail'}" value="{!item.rail__c}"/>
</apex:column>
</apex:pageBlockTable>
i have a VF page code
<apex:pageBlockSection collapsible="false" columns="2" >
<apex:inputField value="{!Opp.field1__c}"/>
<apex:inputField value="{!Opp.field2__c}"/>
<apex:outputField value="{!Opp.field3__c}"/>
<apex:outputField value="{!Opp.field4__c}"/>
</apex:pageBlockSection>
I want to have a command button inside the blockSection. Can we have something like a colspan on table to merge the first line to a single column to hold the command button?
Thanks
Prady
pageBlockSection renders as a table inside a div, so once you are "inside" you can just piggyback on that schema (at least until they change how they render sections). You need two columns per section column (in your case 2x2=>4). Use the following
<apex:pageBlockSection collapsible="false" columns="2" >
<tr>
<td colspan="4">
<apex:commandButton ...>
</td>
</tr>
<apex:inputField value="{!Opp.field1__c}"/>
<apex:inputField value="{!Opp.field2__c}"/>
<apex:outputField value="{!Opp.field3__c}"/>
<apex:outputField value="{!Opp.field4__c}"/>
</apex:pageBlockSection>