Create an interface ITrigger as following public interface ITrigger { /** * bulkBefore * * This method is called prior to execution of a BEFORE trigger. Use this to cache * any data required into maps prior execution of the trigger. */ void bulkBefore(); /** * bulkAfter * * This method is called prior toContinue reading “Trigger Factory Pattern”
Category Archives: Uncategorized
Trigger.newmap & trigger.oldmap
Where we use (trigger events) trigger.newmap & trigger.oldmap? newMapA map of IDs to the new versions of the sObject records.Note that this map is only available in before update, after insert, and after update triggers. oldMapA map of IDs to the old versions of the sObject records.Note that this map is only available in updateContinue reading “Trigger.newmap & trigger.oldmap”
Using Query String Parameters in a Visualforce Page
To access query string parameter value in custom controllerString value = ApexPages.currentPage().getParameters().get(‘name’); To access query string parameter value in visual force page{!$CurrentPage.parameters.name} To setting param valueApexPages.currentPage().setParameters().put(‘name’, ‘sandeep’); The setParameters() method is only valid inside test methods.
Loading Image concept in salesforce
Where you can use this in salesforce??When you have rerender some another fields based on picklist value change. Add following line of code to your css file #loading-image { position: fixed; top: 40%; left: 50%;}#loading { width: 100%; height: 100%; top: 0px; left: 0px; position: absolute; display: none; opacity: 0.5; filter: alpha(opacity = 50); -moz-opacity:Continue reading “Loading Image concept in salesforce”
Showing and hiding Pop-up
Add following line of code to your css file .black_overlay{ display: none; position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index:1001; -moz-opacity: 0.8; opacity:.80; filter: alpha(opacity=80);}.white_content { background-color: white; border: 5px solid #0f2c52; border-radius: 10px; display: none; height: 21px; left: 37%; overflow: auto; padding: 10px; position: fixed; text-align: center; top: 40%;Continue reading “Showing and hiding Pop-up”
Mass submit approval process through apex code
/******************This method assign selected applications to selected user/queue*************/public PageReference assignApplication() { PageReference pageRef = null; List requests = new List(); SavePoint sp = Database.setSavePoint(); try { for(ApplicationWrapperClass appWrapper : applicationWrapperList) { if(appWrapper.isSelected) { Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest( ); req.setComments(‘Submitted for approval. Please approve.’); req.setObjectId(appWrapper.application.Id); req.setNextApproverIds(new List{selectedUserOrQueue}) ; requests.add(req); } } update applicationList; Approval.process(requests); successContinue reading “Mass submit approval process through apex code”
Querying DateTime field in SOQL dynamically
Export_String_Batch__c batchSettings = Export_String_Batch__c.getInstance(‘DEFAULTS’); //fetching record from custom setting list.String str = ((DateTime)batchSettings.LastExecutedDate__c).format(‘yyyy-MM-dd\’T\’hh:mm:ss\’Z\”);String queryStr = ‘SELECT Id FROM Account WHERE CreatedDate =’+str;List current = database.query(queryStr);
Optimized class to reduce Describe limit in salesforce
/***The purpose of this class is to reduce the Describe limits and increasing performance of your app*author:Sandeep**/public class SchemaCache { private static Map gdMap {get;set;} private static Map dsrMap = new Map(); private static Map dfrMap = new Map(); private static Map<String, Map> sObjFldMap = new Map<String, Map>(); //Only retrive map of sobjects if notContinue reading “Optimized class to reduce Describe limit in salesforce”
What is heap?
Heap is the amount of memory being referenced by your running code. All the object that you create in your code is added up to heap thereby increasing heap size. When object dies or garbage collected ,memory goes back to Heap space.
Obtaining sObject Describe Results Using Tokens
To access the describe result for an sObject, use one of the following methods: Call the getDescribe method on an sObject token. Use the Schema sObjectType static variable with the name of the sObject. For example, Schema.sObjectType.Lead. Schema.DescribeSObjectResult is the data type for an sObject describe result. The following example uses the getDescribe method on an sObject token: Schema.DescribeSObjectResult dsr = Account.sObjectType.getDescribe(); TheContinue reading “Obtaining sObject Describe Results Using Tokens”
Selecting and deselecting multiple checkboxes
Add following javascript codefunction toogleAllCheckboxValue(val) { $(‘.isSelect’).prop(‘checked’, val);}function setCheckboxHeaderValue(val) { //alert(val); if(!val) { $(‘.checkBoxHeader’).prop(‘checked’, val); } else { var flag = true; $(‘.isSelect’).each(function() { if(!$(this).is(‘:checked’)) { $(‘.checkBoxHeader’).prop(‘checked’, false); flag = false; return false; } }); if(flag) { $(‘.checkBoxHeader’).prop(‘checked’, true); } }} Below is the screenshot which shows how these functions are related to checkboxes
Loading Image
Loading Image is used during processing of record. Add following css#loading-image { position: fixed; top: 40%; left: 50%;}#loading { width: 100%; height: 100%; top: 0px; left: 0px; position: absolute; display: none; opacity: 0.5; filter: alpha(opacity = 50); -moz-opacity: 0.5; background-color: #fff; text-align: center; z-index: 100;} Add following javascript code//function for showing loading imagefunction showLoadingImage() {Continue reading “Loading Image”
Restrict Number of characters in text box
Use maxLength property to set maximum limit in a textbox. Sample code is shown below- var ele = document.getElementById(‘txt’); ele.maxLength = 5;
Disabling a link through css
Suppose you have link in html as shown below with id = ‘linkClass’ <a href=”link.html” class=”linkClass”>Link , write following lines as css code.linkClass { pointer-events: none; cursor: default;} Now your link is disabled.
Add Speech Input to your Search Box
Apex: How to get parameter values and how to test them?
When writing unit tests for controller extension and custom controller classes, you can set query parameters that can then be used in the tests. For example, the following custom controller and markup is based on the example from Controller Methods, but has been extended to expect the following query parameter in the URL for theContinue reading “Apex: How to get parameter values and how to test them?”
Parsing the JSON object in salesforce
For example- Its a JSON output. We have to parse this.{ “CompanyContacts”: [ { “contact”: “pn0”, “postalcode”: “0”, “contactnumber”: “pc0” }, { “contact”: “pn1”, “postalcode”: “1”, “contactnumber”: “pc1” }, { “contact”: “pn2”, “postalcode”: “2”, “contactnumber”: “pc2” } ]} public class CompanyContacts{ public List CompanyContacts;}public class CompanyContactsWrapper{ public String contact; public String postalcode; public String contactnumber;}Continue reading “Parsing the JSON object in salesforce”
How to change field label using code when fields are fetched through fieldset. (Optimised Approach)
Please Note: This is not a complete code. I am showing here only the concept. To understand the concept, you must have prior knowledge of fieldset. Please write your comment or mail me at sandeep.saini482@gmail.com if you want elaboration of full code. public Map mapFieldLabels{get;set;}//call this method in constructorpublic methodTosetLabel() { mapFieldLabels = new Map();Continue reading “How to change field label using code when fields are fetched through fieldset. (Optimised Approach)”
How to show error message on salesforce site?
You can use the property to show show error message on site. Below is an example which is self explanatory. public String err{get;set;} //property public void method1() { try { //statements } catch(Exception e) { err = e.getMessage(); }} Now you can use this property on page in this simple way or in advance asContinue reading “How to show error message on salesforce site?”
How to show customised error message on vf page?
Write the following line ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ‘Customised Error Message’)); instead of ApexPages.addmessages(e);
How to get parameter value from url in apex?
Write the following line in constructor. Value of the param ‘id’ is stored in paramValue. String paramValue = ApexPages.currentPage().getParameters().get(‘id’);
How to pass Salesforce dev 401 Certification Exam?
If you want to pass dev 401 exam with full confidence, then use the following three steps:- 1. You should read all salesforce tutorials first. Here is the linkhttp://www.salesforcetrainingpodcasts.com/podcasts/401/2. You should read dev 401 dumps.3. Go for 4-5 mock dev 401 exams for your self analysis. If you score more than 90% in these mockContinue reading “How to pass Salesforce dev 401 Certification Exam?”
How to change label of a field while using fieldset.
See the following example public Map mapFieldLabels{get;set;}//constructorpublic DemoClass { mapFieldLabels = new Map(); Schema.DescribeSObjectResult d = Application__c.sObjectType.getDescribe(); Map mapFields = d.fields.getMap(); for (Schema.FieldsetMember member : getEnrollmentQuestionsFields()) { if (member.fieldpath == ‘Entry_Type__c’) { mapFieldLabels.put(member.fieldpath,’Entry status’); } else if (member.fieldpath == ‘Start_Term_of_Interest__c’) { mapFieldLabels.put(member.fieldpath,’For which term are you applying?’); } else if (member.fieldpath == ‘Start_Year_of_Interest__c’) { mapFieldLabels.put(member.fieldpath,’ForContinue reading “How to change label of a field while using fieldset.”
How to check whether which line got compile error?
Following code will show error message as well as the line which contains the error message. try {//Your Code} catch(Exception e) {Apexpages.addMessage(new Apexpages.Message(Apexpages.severity.ERROR, e.getMessage() + ‘***’ + e.getStackTraceString()));}
How to add parameter to page url through apex code?
Use the getParameters() and put() methods to add parameters to the URL.Example: pageRef = getParameters().put(‘id’, object.id);
Retriving a fieldset of an Object
Description Represents a field set. A field set is a grouping of fields. For example, you could have a field set that contains fields describing a user’s first name, middle name, last name, and business title. Field sets can be referenced on Visualforce pages dynamically. If the page is added to a managed package, administratorsContinue reading “Retriving a fieldset of an Object”
How to allow calender to show more years?
1. Add datepicker_extend.js file in static resoource with name as datepicker_extend. You can download extend.js from this below link download datepicker_extend.js 2. Create a component. Component Name : DatePickerExtend $(function(){ var PRELIMIT = parseInt(“{!lowerLimit}”); var POSTLIMIT = parseInt(“{!higherLimit}”); var startYear = parseInt(“{!startYear}”); var endYear = parseInt(“{!endYear}”); if(!startYear && PRELIMIT){ startYear = $(“#calYearPicker option:first”).val(); endYear =Continue reading “How to allow calender to show more years?”
Checkbox in DataTable
We have to use wrapper class for displaying the check box in a data table or page block table. I am providing sample code which creates new contact, save and delete selected contact records of respective Account. Page: Apex Code: public class CustomAccountController { public Account acc{get;set;} private Id AccId{get;set;} public List contactList{get;set;} public contactContinue reading “Checkbox in DataTable”
logging out of customer portal using a button
1. On button click, redirect the user to the url provided in below example to log out of customer portal. public PageReference LogOut() { return new PageReference(‘/secur/logout.jsp’); } 2. You can also try this for html link Logout
Display a Multi-picklist as Checkboxes
Assume Military_Branches__c is of multipicklist type but you want to display it as check boxes on VF page. Task1: created a VF page and write following codes between pageblocksection. Task 2: create a method in controller which will return the list of selectOptions public List militaryBranch{get;set;} //this will contain the values of selected checkboxespublic ListContinue reading “Display a Multi-picklist as Checkboxes”
Best way to debug your code.
This example will show how to debug code in a short and best way. You have to use System.assert to expose your code for debugging purpose. Lets Assume-You have created a page which uses DemoController and which are not showing expected value on the page . So you want to debug the value of NameContinue reading “Best way to debug your code.”
What to do when there is problem in displaying field value on page.
Field may be hidden due to field level security or might be that it doesn’t contain any value. If this is the problem, then write following apex code: /*showing whether contact.FirstName contains a value*/public class DemoController { public Contact contact; public DemoController () { contact = [Select Name from Contact][0]; System.assert(false, contact.Name); }} /*If theContinue reading “What to do when there is problem in displaying field value on page.”
Disabling calendar feature on VF page for Date type Fields
To disable calendar feature add following class in your css to disable calender feature for datetype field. .dateFormat {display:none;} and set standardStylesheets=”false”.