Newbie at visualforce - salesforce

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"/>

Related

Salesforce: Creating a User Registration Form using VisualFocre

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'));
}
}

How we can get the Mandatory sign in the Visual Force of SFDC?

I am new to the Visual Force code of the SDFC. I wanted to get the Mandatory details need sign shown below on my developed code of "Entry Section" of pageBLockSection. How Can I do that ?
<apex:page standardController="account">
<apex:form>
<apex:pageBlock title="Block One">
<apex:pageBlockSection title="Entry Section">
<apex:inputField value="{!account.Name}"/>
<apex:inputField value="{!account.phone}"/>
<apex:inputField value="{!account.billingcity}"/>
<apex:inputField value="{!account.Industry}"/>
<apex:commandButton value="Submit" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
To make a input tag required, set required = 'true' for the input.
Ex, <apex:inputtext value="{!Name}" required="true"/>

Custom Field Labels - Field Sets VisualForce

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)}" />

How do I customize the columns in a apex:listView?

I have a apex:listView for my Cases:
<apex:ListViews type="Case">
</apex:ListViews>
When I display this page, I get the columns Action, Case Number, Contact Name, Subject, Status, Priority, Date/Time Opened, and Case Owner Alias.
How would I customize which columns show up and what order the columns are in?
Thanks.
This is what I ended up doing:
<apex:page standardController="Case" recordSetVar="Case" sidebar="true" showHeader="true">
<apex:form >
<apex:pageBlock title="Cases">
<apex:outputLabel value="View:"/>
<apex:selectList value="{!filterId}" size="1">
<apex:actionSupport event="onchange" rerender="cases_table"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>
<apex:pageBlock >
<apex:pageBlockButtons >
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!case}" var="c" rows="50" id="cases_table" >
<apex:column >
<a target="_parent" href="{!URLFOR($Action.Case.View, c.id)}">{!c.CaseNumber}</a>
<apex:facet name="header">Case Number</apex:facet>
</apex:column>
<apex:column value="{!c.ContactId}" />
<apex:column value="{!c.Subject}" />
<apex:column value="{!c.Status}" />
<apex:column value="{!c.Priority}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
<base target="_parent"/>
</apex:page>
Apex List Views, similar to standard list views, contain a picklist at the top followed by an Edit button and a Create New View button. You can modify the view by clicking on the Edit button. There is no way, that I am aware of, to modify the columns programmatically. If you need more control, you could use another tag, such as <apex:pageblocktable>, as JCD mentioned in the question comments.

Display fields based on Checkbox actions

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>

Resources