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
alexander yurpolskyalexander yurpolsky 

Newbie at visualforce

Hello,

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>


</apex:page>

https://ibb.co/iWSVVS
 
  1. The field "Campaign name" is a required field how can i add the red bar next to the field
  2. 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

 
Raj VakatiRaj Vakati
Please see my comments here .. 
1 .  The field "Campaign name" is a required field how can i add the red bar next to the field? 
Raj: You can do it by using apex: input field which will response the required 
 
<apex:inputfield value="{!Campaign.name}" id="name" />

2.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".

Raj: You can do it by using server-side apex controller or client-side javascript
Gaurish Gopal GoelGaurish Gopal Goel
Hi Alex,

1. For red marker on Campaign field or any other field which you want to make mandatory, you can use required="true"
<apex:inputfield value="{!Campaign.name}" required="true" />

2. Combining two or more values, you can refer the below code:
PAGE:
<apex:inputText value="{!firstValue}" />
<apex:inputText value="{!secondValue}" />

CONTROLLER:
public class abc
{
public string firstValue{get;set;}
public string secondValue{get;set;}
public pageReference save()
{
Campaign.Name = firstValue+'-'+secondValue;
update campaign;
return null;
}
}

If this answer solves your problem then mark it as the solution to help others. Thanks.