Another Salesforce blog!!!

Salesforce, Apex

January, 2017

PageReference

public PageReference goBack() { PageReference pr = Page.DC_TableDetail; pr.getParameters().put(‘tblId’,tblId); pr.getParameters().put(‘colId’,colId); return pr; } <apex:repeat value=”{!Employees}” var=”e” id=”r”> <apex:commandLink value=”{!e.Name}” action=”{!clickOnName}”> <apex:param name=”eId” value=”{!e.Id}” assignTo=”{!empId}”/> </apex:commandLink> </apex:repeat> public Id empId{get; set;} public PageReference clickOnName() { system.debug(‘clickOnName//’ ); PageReference newPage = Page.NewEmployee; newPage.getParameters().put(’empId’, empId); return newPage.setRedirect(true); }

ApexPages currentPage()

String id = ApexPages.currentPage().getParameters().get(‘id’); if(id != ” || id != null) { //… }

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( ‘_’, ‘ ‘);

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;

lazyload loading

public Employee__c[] employees { get { return employees == null ? employees = [some soql]; : employees; } set; }

PageReference redirecting from the Visualforce page

if you are passing any parameters then you would use this: <apex:outputLink value=”{!URLFOR($Page.NewEmployee, null, [empId=e.Id])}”> e.Name </apex:outputLink> If you want to add more parameters, you can add them in between the square brackets. [empId=e.Id,id=URLENCODE($CurrentPage.Parameters.Id)]

Render IF-Else in the Visualforce page block

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