Posts

Showing posts from October, 2014
Image
Difference between renderAs, rendered and reRender 1. RenderAs : it is used with page component with name of any supported content converter. Currently only PDF is the only supported content converter. example: below code will give output in pdf form <apex:page standardController="Account" renderAs="pdf">     <apex:pageBlock title="welcome {!$User.FirstName}, ">         <apex:pageBlockSection columns="1" title="here is your Account Detail :">             <apex:outputField value="{!account.Name}"/>             <apex:outputField value="{!account.AccountNumber}"/>         </apex:pageBlockSection>     </apex:pageBlock> </apex:page> 2. Rendered : it use to show or hide visualforce elements. It is bound Boolean value in controller which can...
Image
What is My Salesforce Edition Have you ever came across a situation where you need to know what is your Salesforce Org edition. If yes what you have done ?  There are few easy ways to find out Salesforce edition. 1. From your web browser's Salesforce tab Hover mouse over your salesforce tab in your web browser               in above snapshot text appears as "salesforce.com - Developer Edition "   when lands on Account tab text changes to "Accounts: Home ~ salesforce.com - Developer Edition " but the edition name always mentioned at last "Developer Edition", It will work for other edition as well.     2. Second way to find out the edition is by clicking  SETUP > ADMINISTER   Hope this will help
Image
Filter Records by Running User Sometimes we want to see the records created by different User in Org and to achieve this we always create many custom list views having filter criteria "Owner Last Name " or "Owner First Name " which is fine if you few users but what will you do if number of users are large. You surely not going to create list view. This limitation can be overcome by creating few formula fields and a list view. Scenario:-  Wanted to see the list of Account assigned to a particular Users. 1. To achieve this create one formula field [ Name = 'Formula Owner ' ]of type Number and decimal set to 0, and in formula editor write IF( Owner.Id = $User.Id, 1, NULL)      Owner.Id represents Id of Owner of account     $User.Id represent/give the Id os logged in User and save the formula field. 2. Now to go Accounts and creates a new List view, where filter criteria would be  F...
Image
Using colon in Report Name While naming the reports we can separate the name to display on 2 separate lines. Its not been documented anywhere from Salesforce. I came to know about it from Scott Hemmeter .  While naming the report separate the name with colon which will make reports to appear on two separate lines. example : if you name your report as "Developer Org Dummy Account Report " it will appear as   and if you name your report as "Developer Org : Dummy Account Report   " it will appear as  
Image
Salesforce.com Unique Field Limitation   Salesforce have some of the limitation and one of it is number of unique fields per object. Salesforce only allow 7 fields as ExternalId per object and also consider Unique fields as ExternalId. If you already have 7 fields which are marked as ExternalId or UniqueId or both then you will receive an error if you try to create a new field as Unique/External   and you try to make field unique it will show an error if that field in more than one record contains same value. only Email, Text, Number fields can be marked Unique
Set Parameter in Test Class While writing test classes we often stuck with some parameters which need to be set to test the logic further, some developers try to avoid those parameters with Test.isRunning() in there logic which is not a good practice. Salesforce powers us to set those parameter in Test Class. Suppose I am passing an Id of an Account in my url and on basis of Id I am querying Account. public with sharing class ParameterController {        private Id accId;     public Account accDetail{get;set;}     public ParameterController() {         accId = ApexPages.CurrentPage().getParameters().get('Id');     }        public void accountDetails() {         system.debug('  Account Id ' + accId);         accDetail = [Select Id, Name, AnnualRevenue From Account Where I...
DML Options We can use DML options while inserting or updating by setting desired options in Database.DMLOptions object. We can set options either by calling Databse.DMLOptions "SetOptions "method or by passing it as parameter to Database.insert or Database.Update methods. Database.DMLOptions have following property 1. allowFieldTruncation : From Apex version 15 and higher if any field value is too large error message generated and operation gets failed. Using allowFieldTruncation we can truncate the string. Syntax:   Database.DMLOptions dml = new Database.DMLOptions();           dml.allowFieldTruncation = true; 2. assignmentRuleHeader :   Allow us to specifies if assignment rule to be used while creating Lead or Case with assignmentRuleHeader we can set following options     a. useDefaultRule : Indicates whether default (active) assignment rule to be used for Lead or Case.     b. assignmentR...
Creating Parent and Child Records in Single Statement Inserting Parent and Child record in single statement is commonly asked question in Interviews. This could be achieved using external ID fields instead of inserting parent record then querying its ID and then inserting Child record. Let take an example, I want to insert Account and Contact records in single insert DML statement. To do so I will first create Contact Object and populates some of its fields, then creates two Account objects. First account is only for foreign key relationship and other for account creation. Both account have ExternalId field. Then we will call database.insert by passing it an array of sObjects. First element in array will be parent sObject and second element will be child sObject. // Child record Contact newContact = new Contact(FirstName = 'Child', LastName = 'Contact', Email = 'puneetmishrasfdc@gmail.com'  ); // Creating reference Account Account account...
Apex DML Statements Apex allow us to perform Data Manipulation Language (DML) operations to insert, update, merge, delete, and restore data in a database. Following DML Statements are available 1. Insert :   Insert DML operation adds one or more sObjects records to our organisation. Syntax: insert sObject[ ] 2. Update : Update DML operation modifies one or more existing sObject records in our organisation's data  Syntax : update sObject[ ] 3. Upsert : Upsert DML operation creates new sObject records and updates the existing sObject records within single statement, externalId can be used with upsert Statement. Syntax : upsert sObject[ ]  extenal_Id external_Id should be used to identify the record that already exist in organisation's data.  NOTE : if custom field declared as externalId does not have unique attribute selected, the context user must have "View All" object level permission for the target object or the ...