Another Salesforce blog!!!

Salesforce, Apex

IMPORTANT

Custom settings: How to get the data

SO_Country__c code = ISO_Country__c.getInstance(‘name_of_the_custom_settings’); //To return a map of data sets defined for the custom object (all records in the custom object), //you would use: Map<String,ISO_Country__c> mapCodes = ISO_Country__c.getAll(); // display the ISO code for India System.debug(“˜ISO Code: “˜+mapCodes.get(‘name_of_the_custom_settings’).ISO_Code__c); //Alternatively you can return the map as a list: List<String> listCodes = ISO_Country__c.getAll().values();

restrict any Trigger to fire only once

how we can avoid repeated or multiple execution of Trigger? Triggers can fire twice, once before workflows and once after workflows, this is documented at http://www.salesforce.com/us/developer/docs/apexcode/ Content/ apex_triggers_order_of_execution.htm: “The before and after triggers fire one more time only if something needs to be updated. If the fields have already been set to a value, the […]

static resources in Visualforce

CSS File: <apex:stylesheet value=”{!URLFOR($Resource.style_resources, ‘styles.css’)}”/> Relative path in CSS from static resource, You can use relative paths in files in static resource archives to refer to other content within the archive. table { background-image: img/testimage.gif } Image tag: <apex:image url=”{!$Resource.TestImage}” width=”50″ height=”50″/> or <apex:image url=”{!URLFOR($Resource.TestZip, ‘images/Bluehills.jpg’)}” width=”50″ height=”50″/> Include Javascript in Visualforce from Static resource […]

triggers: pattern

/***************************************************************************** * Trigger : XXXTrigger * Description : XXX__c trigger to handle DML operations through XXXTriggerHelper class * 1. After insert; * 2. After update; * * Project : XXXXX * Author : XXXXX * Date : XXXXX * Version : 1.0 * * Version History : * *****************************************************************************/ trigger XXXTrigger on OBJECT_NAME__c (before insert, […]

writing test classes in apex

private static List<User> agentUsers; private static List<Profile> agentProfiles; agentProfiles = [select id from Profile where Name LIKE ‘%Agent%’ limit 1]; agentUsers = TestDataUtil.createUsers(1, true, new Map<string, object>{ ‘FirstName’ => ‘JOHN’, ‘Email’ => ‘test3@test.com’, ’emailencodingkey’ => ‘UTF-8’, ‘languagelocalekey’ => ‘en_US’, ‘localesidkey’ => ‘en_US’, ‘Username’ => ‘agent@test.com’, ‘timezonesidkey’ => ‘America/Los_Angeles’, ‘CommunityNickname’ => ‘agentCommNickName’, ‘profileId’ => agentProfiles[0].Id } […]

Maps in Apex

MAP: Map<ID, Contact> m = new Map<ID, Contact>([SELECT Id, LastName FROM Contact]); for(id myid : m.keyset()) { system.debug(‘///’ + m.get(myid).LastName); } Map<ID, Contact> m = new Map<ID, Contact>([SELECT Id, LastName FROM Contact]); for(id myid : m.keyset()) { system.debug(‘///’ + m.get(myid).LastName); } Map<id, id> newRAEMap = new Map<Id, Id>(); newRAEMap.put(aAd_Board.id, aAd_Board.RAE__c); for (Id key: newRAEMap.KeySet()){ if […]

Creating a Controller Extension

Creating a Controller Extension <apex:page standardController=”Speaker__c” extensions=”SpeakerControllerExtension”> public with sharing class SpeakerControllerExtension { public Integer counter {get; set;} private final Speaker__c speaker; private ApexPages.StandardController stdController; public SpeakerControllerExtension(ApexPages.StandardController stdController) { this.speaker = (Speaker__c)stdController.getRecord(); this.stdController = stdController; counter = 0; } public void increment() { counter++; } }

INPUTBOX WITH PAGINATION

<apex:page controller=”PaginationWithInputTextController”> <apex:form id=”form”> <apex:actionFunction name=”updateQuantity” action=”{!updateQuantity}” rerender=”pb”> <apex:param name=”contextItem” value=”” assignTo=”{!contextItem}”/> <apex:param name=”contextItemValue” value=”” assignTo=”{!contextItemValue}”/> </apex:actionFunction> <apex:pageBlock title=”Account Details” id=”noRec” rendered=”{! IF(AccountWraps != null && AccountWraps.size ==0 , true, false)}” > <apex:outputPanel > <h1>No Records Found </h1> </apex:outputPanel> </apex:pageBlock> <apex:pageBlock title=”Account Details” id=”pb” rendered=”{! IF( AccountWraps != null && AccountWraps.size >0, true, false)}” > […]

checkbox with pagination

<apex:page controller=”PaginationWithCheckboxController”> <apex:form id=”form”> <apex:actionFunction name=”aSelectItem” action=”{!doSelectItem}” rerender=”pb”> <apex:param name=”contextItem” value=”” assignTo=”{!contextItem}”/> <!–apex:param name=”contextItemValue” value=”” assignTo=”{!contextItemValue}”/–> </apex:actionFunction> <!– handle deselected item –> <apex:actionFunction name=”aDeselectItem” action=”{!doDeselectItem}” rerender=”pb”> <apex:param name=”contextItem” value=”” assignTo=”{!contextItem}”/> </apex:actionFunction> <apex:actionFunction name=”isSelectAllItem” action=”{!isSelectedAll}” rerender=”pb”> <apex:param name=”isSelectedALL” value=”” assignTo=”{!selectedAllProperties}”/> </apex:actionFunction> <apex:pageBlock title=”Account Details” id=”noRec” rendered=”{! IF(AccountWraps != null && AccountWraps.size ==0 , true, false)}” > […]

checkbox pagination using Database.getQueryLocator

Visualforce page: <apex:page controller=”ContactTable” sidebar=”false”> <apex:form id=”myform”> <apex:pageblock title=”Maintaining Selected Records”> <apex:pageBlockButtons location=”Top”> <apex:commandButton value=”Processed” action=”{!clickMe}” /> </apex:pageBlockButtons> <!– In our table, we are displaying the Contact records –> <apex:pageblocktable value=”{!Contact}” var=”cc” > <apex:column headerValue=”Choose Contact”> <!– This is our selected Boolean property in our wrapper class –> <apex:inputCheckbox value=”{!cc.bool}”/> </apex:column> <!– This is how […]

Previous Posts