Tag Archives: Visualforce Page

Radio Button in Visualforce Page

<apex:page >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >Gender
                    <apex:selectRadio >
                        <apex:selectOption itemLabel="Male" itemValue="m"/>
                        <apex:selectOption itemLabel="Female" itemValue="f"/>           
                    </apex:selectRadio>     
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Custom Label in Salesforce

Custom labels enable developers to create multilingual applications by automatically presenting information (for example, help text or error messages) in a user’s native language. Custom labels are custom text values that can be accessed from Apex classes, Visualforce pages, or Lightning components. The values can be translated into any language Salesforce supports.

We can create up to 5,000 custom labels for your organization, and they can be up to 1,000 characters in length.

Setup | App Setup | Custom Labels | Click ‘New Custom Label’ Button

Fill in the details and Click ‘Save’ button.

 

Custom Label in Visualforce page:
$Label.CustomLabel for Visualforce page.

<apex:page standardController="Account">
	
<h1>Example for Custom labels</h1>

	<apex:outputLabel value="{!$Label.Message}"/>
</apex:page>

 

Custom Label in Apex Class:
System.Label.Label_name for apex class

String msg = System.Label.Message; 

 

Custom Label in Lightning Component:
$Label.c.labelName for the default namespace.
$Label.namespace.labelName if your org has a namespace, or to access a label in a managed package.

<aura:component implements="flexipage:availableForAllPageTypes">
    
<div onclick="{!c.clickLabel}">
        <ui:outputText value="{!$Label.c.Message}" />
    </div>

</aura:component>

 

Custom Label in Javascript:
$A.get(“$Label.c.labelName”) for the default namespace.
$A.get(“$Label.namespace.labelName”) if your org has a namespace, or to access a label in a managed package.

({
    clickLabel : function(component, event, helper) {
        var label = $A.get("$Label.c.Message");
        alert(label);
    }
})

Summary field as footer of pageblock table in Visualforce page.

In this post I’ll show, how can we add the summary field or total amount or other information in footer of PageBlockTable or DataTable in Visualforce page.

In the below example I’m using the apex:facet name="footer" tag, to show sum of all the opportunity line items of an Opportunity in footer of PageBlockTable.

<apex:page standardController="Opportunity">    
    <apex:pageBlock title="{!Opportunity.Name}">    
        <apex:pageblocktable value="{!Opportunity.OpportunityLineItems}" var="item">
            <apex:column value="{!item.PricebookEntry.Name}"/>
            <apex:column value="{!item.ServiceDate}"/>
            <apex:column value="{!item.Quantity}"/>
            <apex:column value="{!item.UnitPrice}">
                <apex:facet name="footer">
                    <apex:outputText value="Total:" style="float: right;"/>
                </apex:facet>
            </apex:column>
            <apex:column value="{!item.TotalPrice}">
                <apex:facet name="footer">
                    ${!Opportunity.Amount}
                </apex:facet>
            </apex:column>
        </apex:pageblocktable>
    </apex:pageBlock>
</apex:page>

Insert Records in Salesforce by using JavaScript

In this article I’ll demonstrate how to insert record in Salesforce object by using javascript, in VF page without any standard or custom controller or by apex class.

By using AJAX Toolkit we can do this task easily. There are two types of AJAX Toolkit one is synchronous and another one is asynchronous call.

Here is a simple example of data insert using Javascript in Visualforce page. In below example I’m using synchronous call.
These are the steps to insert data using Javascript:

  1. Connecting to the AJAX Toolkit(By using login methods or getting Session_ID).
  2. Embedding the API methods in JavaScript.
  3. Processing the results.

Sample Code:

<apex:page id="pg">
    <script src="/soap/ajax/20.0/connection.js" type="text/javascript"></script>
	<script>
		function insertAcc(){

			// Getting Session ID.
			sforce.connection.sessionId = "{!$Api.Session_ID}";

			//Creating New Account Record.
			var account = new sforce.SObject("Account");

			//Getting Account Name from inputText.
			account.Name = document.getElementById("pg:frm:pb:pbs:pbsi:txtName").value;

			//Create method 
			var result = sforce.connection.create([account]);

			//Getting result 
			if (result[0].getBoolean("success")) {
				alert("New Account is created with id " + result[0].id);
			}
			else {
				alert("failed to create new Account " + result[0]);
			}
		}
	</script>
	<apex:form id="frm">
		<apex:pageBlock title="Insert Account" tabStyle="Account" id="pb">
			<apex:pageBlockSection title="Account Name" columns="1" id="pbs">
				<apex:pageBlockSectionItem id="pbsi">
					<apex:outputLabel value="Name" />
					<apex:inputText title="Name" id="txtName" />
				</apex:pageBlockSectionItem>
			</apex:pageBlockSection> 
			<apex:pageBlockButtons>
				<apex:commandButton onclick="return insertAcc();" value="Save"/>
			</apex:pageBlockButtons>
		</apex:pageBlock>
	</apex:form>
</apex:page>

$Action Global Variable in Salesforce

$Action is a global variable. All objects support basic actions, such as new, clone, view, edit, list, and delete. The $Action global also references actions available on many standard objects.

Example:

<apex:page standardController="Account">
    
    <!--Create Account New Record-->
    <apex:outputLink value="{!URLFOR($Action.Account.New)}">
        Creating New Account
    </apex:outputLink>
    
    <!--Edit Account Record -->
    <apex:outputLink value="{!URLFOR($Action.Account.Edit, Account.Id)}">
        Editing record
    </apex:outputLink>
    
    <!--Delete Account Record-->
    <apex:outputLink value="{!URLFOR($Action.Account.Delete, Account.Id)}">
        Deleting Account Record
    </apex:outputLink>
    
    <!--Navigate to Account List view-->
    <apex:outputLink value="{!URLFOR($Action.Account.List, $ObjectType.Account)}">
        Go to the Account List View
    </apex:outputLink>
    
    <!--Navigate to Account Tab-->
    <apex:outputLink value="{!URLFOR($Action.Account.Tab, $ObjectType.Account)}">
        Go to the Account tab
    </apex:outputLink>
</apex:page>

You can reference following actions with the $Action global variable and the objects on which you can perform those actions.

Value Description Objects
Accept Accept a record.
  • Ad group
  • Case
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Search phrase
  • SFGA version
  • Text ad
Activate Activate a contract. Contract
Add Add a product to a price book. Product2
AddCampaign Add a member to a campaign. Campaign
AddInfluence Add a campaign to an opportunity’s list of influential campaigns. Opportunity
AddProduct Add a product to price book. OpportunityLineItem
AddToCampaign Add a contact or lead to a campaign.
  • Contact
  • Lead
AddToOutlook Add an event to Microsoft Outlook. Event
AdvancedSetup Launch campaign advanced setup. Campaign
AltavistaNews Launch www.altavista.com/news/.
  • Account
  • Lead
Cancel Cancel an event. Event
CaseSelect Specify a case for a solution. Solution
ChangeOwner Change the owner of a record.
  • Account
  • Ad group
  • Campaign
  • Contact
  • Contract
  • Google campaign
  • Keyword
  • Opportunities
  • Search phrase
  • SFGA version
  • Text ad
ChangeStatus Change the status of a case.
  • Case
  • Lead
ChoosePricebook Choose the price book to use. OpportunityLineItem
Clone Clone a record.
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Product
  • Search phrase
  • SFGA version
  • Text ad
  • Custom objects
CloneAsChild Create a related case with the details of a parent case. Case
CloseCase Close a case. Case
Convert Create a new account, contact, and opportunity using the information from a
lead.
Lead
ConvertLead Convert a lead to a campaign member. Campaign Member
Create_Opportunity Create an opportunity based on a campaign member. Campaign Member
Decline Decline an event. Event
Delete Delete a record.
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Opportunity product
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Task
  • Text ad
  • Custom objects
DeleteSeries Delete a series of events or tasks.
  • Event
  • Task
DisableCustomerPortal Disable a Customer Portal user. Contact
DisableCustomerPortalAccount Disable a Customer Portal account. Account
DisablePartnerPortal Disable a Partner Portal user. Contact
DisablePartnerPortalAccount Disable a Partner Portal account. Account
Download Download an attachment.
  • Attachment
  • Document
Edit Edit a record.
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Opportunity product
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Task
  • Text ad
  • Custom objects
EditAllProduct Edit all products in a price book. OpportunityLineItem
EnableAsPartner Designate an account as a partner account. Account
EnablePartnerPortalUser Enable a contact as a Partner Portal user. Contact
EnableSelfService Enable a contact as a Self-Service user. Contact
FindDup Display duplicate leads. Lead
FollowupEvent Create a follow-up event. Event
FollowupTask Create a follow-up task. Event
HooversProfile Display a Hoovers profile.
  • Account
  • Lead
IncludeOffline Include an account record in Connect Offline. Account
GoogleMaps Plot an address on Google Maps.
  • Account
  • Contact
  • Lead
GoogleNews Display www.google.com/news.
  • Account
  • Contact
  • Lead
GoogleSearch Display www.google.com.
  • Account
  • Contact
  • Lead
List List records of an object.
  • Ad group
  • Campaign
  • Case
  • Contact
  • Contract
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Text ad
  • Custom objects
LogCall Log a call. Activity
MailMerge Generate a mail merge. Activity
ManageMembers Launch the Manage Members page. Campaign
MassClose Close multiple cases. Case
Merge Merge contacts. Contact
New Create a new record.
  • Activity
  • Ad group
  • Asset
  • Campaign
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Search phrase
  • SFGA version
  • Solution
  • Task
  • Text ad
  • Custom objects
NewTask Create a task. Task
RequestUpdate Request an update.
  • Contact
  • Activity
SelfServSelect Register a user as a Self Service user. Solution
SendEmail Send an email. Activity
SendGmail Open a blank email in Gmail.
  • Contact
  • Lead
Sort Sort products in a price book. OpportunityLineItem
Share Share a record.
  • Account
  • Ad group
  • Campaign
  • Case
  • Contact
  • Contract
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Search phrase
  • SFGA version
  • Text ad
Submit for Approval Submit a record for approval.
  • Account
  • Activity
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Opportunity product
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Task
  • Text ad
Tab Access the tab for an object.
  • Ad group
  • Campaign
  • Case
  • Contact
  • Contract
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Text ad
View View a record.
  • Activity
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Opportunity product
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Text ad
  • Custom objects
ViewAllCampaignMembers List all campaign members. Campaign
ViewCampaignInfluenceReport Display the Campaigns with Influenced Opportunities report. Campaign
ViewPartnerPortalUser List all Partner Portal users. Contact
ViewSelfService List all Self-Service users. Contact
YahooMaps Plot an address on Yahoo! Maps.
  • Account
  • Contact
  • Lead
YahooWeather Display http://weather.yahoo.com/. Contact