Posts

Showing posts from December, 2013
Image
Error: MIXED_DML_OPERATION Few days back while writting an test class I encounterd an Error stating  System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa):     You will get this Error if you are trying to perform DML on setup and non-setup objects in same Transaction.  Non-Setup objects can be any one of the Standard objects like Account or any Custom objcets, Below are few examples of Setup objects 1.  FieldPermissions 2.  Group You can only insert and update a group in transaction with   other SObject . Other DML operations are not allowed .   3.  GroupMember You can only insert and update a group member in a transaction with other sObjects in Apex Code saved using Salesforce.com API version 14.0 and earlier.   4.  ObjectPermissions 5.  Permissio...
Image
Salesforce Public Calendar and Resource In salesforce we can create an event and that event get displayed on salesforce calendar but what will happen when you want to block an event in some conference room and do not want that conference room should get block by another event on same day and at same time.              We can acheive that using salesforce resource which is actually a very little but useful functionality of Salesforce which is always been overlooked. Using this functionality we can manage office resource, projectors, meetings etc. As according to Salesforce :  "In contrast to users’ individual calendars, public and resource calendars are for managing group activities or shared resources. You can create an unlimited number of calendars ." To add public calendar or resource : 1. Go to Setup > Customize > Activities > Public Calendar and     Resources. 2. Either create new Public Calendar ...
Image
Calculate number of years in formula field If you want to calculate number of years between two dates like calculating someone's age in years from his/her birthdate, you can do it using formula field.  Create a formula field and select return type a number, don't forget to select decimal place to 0. Now in Formula field editor write below formula.  Explaination: IF condition first checks if month of present year is greater than date of birth, if condition is true then age will be calculated as the difference between present year and year of birth, but if condition is false then second IF condition is calculated according to which if month of two dates are same or taday's day is larger than or equal to the day of date of birth then age is calculated as in the first scenario [ YEAR(TODAY()) - YEAR(TODAY()) ] . If these also fail then age is calculated as the difference between present year and year of birth, subtracting 1  [ YEAR(TODAY()) - YEAR(DOB__c)...
Image
Email and Phone Validation Suppose you have created a picklist named Type where you are giving an option of selecting Email or Phone and entering the value in text field and want to validate that text field depending on the value of value selected in picklist. You can achieve this by creating a simple validation rule You have Two fields Type : Picklist value with values Business Email Address Private Email Address Home Phone Mobile Phone Work Phone    2. Value : Text Field All you have to do is to create a validation rule on Value function used: IF(logical_test, value_if_true, value_if_false) :   Checks whether a condition is true, and returns one value if TRUE and another value if FALSE. ISPICKVAL(picklist_field, text_literal) : Checks whether the value of a picklist field is equal to a string literal REGEX(Text, RegEx_Text) : Returns TRUE if Text matches the regular expression RegEx_Text. Otherwise, it returns FALSE....