Another Salesforce blog!!!

Salesforce, Apex

VFP

validate input

public Boolean validateInput(){ if(String.isNotBlank(searchWord)){ searchWord = searchWord.trim(); if(searchWord.length() <3){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, ‘AT_LEAST_3′)); return false; } if(searchWord.isNumeric()){ //if user enters only number add wildcard by default. searchWord =’%’+searchWord+’%’; } return true; }else{ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, ‘Please input at least 3 letters or numbers for search ‘)); } return false; } Favorite

keypress 13 – search on enter

Javascript: <script> function searchOnEnter(evt){ var e = evt || window.event; if(e.keyCode == 13){ var searchButton = document.getElementById(‘{!$Component.theForm.pb.pbs.searchButton}’); searchButton.click(); return false; } } window.onkeypress = searchOnEnter; </script> Visualforce page: <apex:form id=”theForm”> <apex:pageBlock title=”Search” mode=”edit” id=”pb”> <apex:pageBlockButtons location=”bottom” id=”pbs”> <apex:commandButton id=”searchButton” value=”Search” action=”{!searchnow}” /> </apex:pageBlockButtons> </apex:pageblock> </apex:form> Favorite

capitalizing 1st character of each word in a string

String rep_name = ‘this is a test’; List<String> elems = rep_name.split(‘ ‘); rep_name = ”; for (String x : elems) { rep_name += x.substring(0,1).toUpperCase()+x.substring(1,x.length()) + ‘ ‘; } System.debug(‘>>>’+rep_name); Replace ‘_’ with space?: string sText = ‘ancestor_concept_id’; sText = sText.replaceAll( ‘_’, ‘ ‘); Favorite

Error, “List has no rows for assignment to SObject”

It would be safer to do the following: Player__c[] players = [SELECT Id from Player__c where Name = :username]; if (players.size() > 0) p = players[0].Id; Favorite

Render IF-Else in the Visualforce page block

{!IF(NOT(ISBLANK(columnDetail.column_Detail_Name)),columnDetail.column_Detail_Name,’No Curated Name’)} Favorite

Converting GMT into Locale Users Time Zone

String timeZone = UserInfo.getTimeZone().getID(); Datetime dateGMT=System.now();// here you can user your dates e.g. createddate Datetime d1=Datetime.valueOf(dateGMT); string s1=d1.format(); System.debug(‘@@@@@@@@@@@’+s1); Favorite

TimeZone with Visualforce page date/time

Some months ago I had a project where I needed to show what date and time an order was processed in Eastern regardless of who submitted the order and their related timezone. Google will quickly show the light for how to display date/time using the timezone set on the user profile or GMT. So the […]

Please wait message

<apex:page standardController=”Account”> <style> /* This is for the full screen DIV */ .popupBackground { /* Background color */ background-color: black; opacity: 0.20; filter: alpha(opacity = 20); /* Dimensions */ width: 100%; height: 100%; top: 0; left: 0; z-index: 998; position: absolute; /* Mouse */ cursor:wait; } /* This is for the message DIV */ .PopupPanel […]

Pagination using StandardSetController

<apex:page controller=”Pagination_min”> <apex:form > <apex:pageBlock id=”pb”> <apex:pageBlockTable value=”{!Accounts}” var=”a”> <apex:column value=”{!a.Name}”/> <apex:column value=”{!a.Type}”/> <apex:column value=”{!a.BillingCity}”/> <apex:column value=”{!a.BillingState}”/> <apex:column value=”{!a.BillingCountry}”/> </apex:pageBlockTable> <apex:panelGrid columns=”7″> <apex:commandButton status=”fetchStatus” reRender=”pb” value=”|< First” action=”{!setCon.first}” disabled=”{!!setCon.hasPrevious}” title=”First Page”/> <apex:commandButton status=”fetchStatus” reRender=”pb” value=”< Previous” action=”{!setCon.previous}” disabled=”{!!setCon.hasPrevious}” title=”Previous Page”/> <apex:commandButton status=”fetchStatus” reRender=”pb” value=”Next >” action=”{!setCon.next}” disabled=”{!!setCon.hasNext}” title=”Next Page”/> <apex:commandButton status=”fetchStatus” reRender=”pb” value=”Last >|” action=”{!setCon.last}” […]

Ajax wild card search

<apex:page controller=”AjaxWildcardController”> <apex:form > <apex:pageBlock > Type Account Name Here :<apex:inputText value=”{!inputtext}” > <apex:actionSupport action=”{!actionSupMethod}” event=”onkeyup” reRender=”outptText” /> </apex:inputtext> </apex:pageBlock> <apex:pageblock > <apex:pageblocktable value=”{!accList}” var=”acc” id=”outptText”> <apex:column value=”{!acc.name}”/> <apex:column value=”{!acc.accountnumber}”/> </apex:pageblocktable> </apex:pageblock> </apex:form> </apex:page> public class AjaxWildcardController { public string inputtext{get;set;} public List<account> accList{get;set;} public boolean flagshow{get;set;} public AjaxWildcardController(){ flagshow = false; } Public void […]

Previous Posts Next posts