Hey guys, today in this post we are going to learn about How to retrieve and split the dropdown picklist values in Visualforce page Salesforce.
In this scenario, We will fetch the currency picklist value based on Quote Record Id and split from currency and it’s currency code uses of Apex class method in Visualforce. To know more details, Click Here.
Final Output β
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
- Find the below steps βΎ
Create Visualforce Page
Step 1:- Create Visualforce Page : splitCurrencyVf.vfp
From Developer Console >> File >> New >> Visualforce Page
splitCurrencyVf.vfp [Visualforce Page]
<apex:page standardController="Quote" extensions="splitCurrencyVfCtrl">
<div class="slds slds-p-around_small" style="padding:10px;">
<table width="50%" border="1" cellspacing="0" cellpadding="5" bordercolor="#ddd" class="slds-table slds-table_bordered slds-table_col-bordered" style="border-collapse:collapse;">
<tr>
<th><strong style="color:#009ee6;">Quote Name</strong></th>
<th><strong style="color:#009ee6;">Line Item Currency</strong></th>
</tr>
<apex:repeat value="{!quoteObj}" var="qotItem">
<tr>
<td><p><strong><apex:outputText value="{!qotItem.Name}"/></strong></p></td>
<td>
<apex:variable var="index" value="{!1}" />
<table width="100%" border="1" cellspacing="0" cellpadding="5" bordercolor="#ddd" class="slds-table slds-table_bordered slds-table_col-bordered" style="border-collapse:collapse;">
<apex:repeat value="{!qotItem.QuoteLineItems}" var="qLine" id="theRepeat">
<tr>
<td width="10%">1.{!index}.</td>
<td><apex:outputText value="{!qLine.Currency__c}"/></td>
<apex:variable var="index" value="{!index + 1}" />
</tr>
</apex:repeat>
</table>
</td>
</tr>
</apex:repeat>
</table>
</div>
</apex:page>
Create Apex Class Extension Controller in Visualforce
Step 2:- Create Apex Class : splitCurrencyVfCtrl.apxc
From Developer Console >> File >> New >> Apex Class
splitCurrencyVfCtrl.apxc [Apex Class Controller]
public class splitCurrencyVfCtrl {
public String MstrId{GET;SET;}
public Quote quoteObj{GET;SET;}
public String curyCode{GET;SET;}
public String currName{GET;SET;}
public splitCurrencyVfCtrl(ApexPages.StandardController Controller){
//QuoteLineItems
MstrId = ApexPages.currentPage().getParameters().get('id');
quoteObj = [SELECT Id, Name, (SELECT Id, Currency__c FROM QuoteLineItems) FROM Quote WHERE Id=:MstrId ];
INTEGER childSize;
system.debug('qItm# ' + quoteObj.QuoteLineItems);
FOR(QuoteLineItem qItm:quoteObj.QuoteLineItems){
IF(qItm.Currency__c !=NULL ){
curyCode = qItm.Currency__c.split('-').get(1);
qItm.Currency__c =curyCode;
system.debug('curyCode## ' + curyCode);
}
}
childSize = quoteObj.QuoteLineItems.size();
system.debug('childSize ' + quoteObj.QuoteLineItems.size());
}
}
Further post that would you like to learn in Salesforce
How do I split a multi select picklist value in Salesforce?
Multi select picklist values are stored semi colon seperated in database. So you can split them by semi colon ' ; ' to get seperated values.
What is split () used for?
The split() function can be used to split a given string or a line by specifying one of the substrings of the given string as the delimiter.
How to get the values from the visualforce page to controller?
In the VF page we have used param at two places, one in the commandbutton and the other in actionfunction. The param which is in the command button has a value specified to it and also assigned to a variable in controller. This value will be passed to the variable in the controller if the button is clicked.
Related Topics | You May Also Like
Our Free Courses β
π Get Free Course β
![]() π Salesforce Administrators π Salesforce Lightning Flow Builder π Salesforce Record Trigger Flow Builder |
π Get Free Course β
![]() π Aura Lightning Framework π Lightning Web Component (LWC) π Rest APIs Integration |