Posts

Showing posts from 2016

Utility class for Apex Sharing

Ever faced a situation where you need to share records and it cannot be achieved through standard sharing rules? In such cases, Apex Managed Sharing comes to your rescue. Let us first try to understand what sharing means. In an org where the OWD is restricitive (OWD is set other than public read/ write or public read only), you may have some requirements where you need to share records with some users.  Sharing  is the act of granting a user or group of users permission to perform a set of actions on a record or set of records. Sharing access can be granted using the Salesforce user interface and Force.com, or programmatically using Apex. To access sharing programmatically, you must use the share object associated with the standard or custom object for which you want to share. For example, AccountShare is the sharing object for the Account object, ContactShare is the sharing object for the Contact object, and so on. In addition, all custom object sharing objects are named as fo

Automate execution of test classes

Image
Schedule your test classes to run daily Many of the projects have a common problem of test coverage when the time for production deployment comes. Generally the development and maintenance of test classes do not go hand in hand with development and maintenance of apex classes. And when the time of deployment comes, you find the your code coverage is below 75%. Usually developers makes changes to code but forgets to make the required changes in test classes. To avoid such scenarios, you can schedule your test classes to run daily and send out the status email to developers so that the test classes are fixed whenever code changes are done. The status report will contain below information How to make this work : The code is uploaded @ Github . You can download all the classes and copy in in your Salesforce org. Schedule the class named "TestClassScheduler" to run daily or weekly as per your requirement. Before scheduling, change the email address in sendEmail method

Trigger Context Variables

Image
Thought of writing a article around the context variables present in triggers. Before Insert :  Trigger.new would be available as new values are being inserted into the database Trigger.old would not be available as fresh records are being inserted into the database Trigger.newMap would not be available as the record id's are not generated in before insert event Trigger.oldMap would not be available as the record id's are not generated in before insert event After Insert :  Trigger.new would be available as new values are being inserted into the database Trigger.old would not be available as fresh records are being inserted into the database Trigger.newMap would be available as the record id's are generated in after insert event Trigger.oldMap would not be available as fresh records are being inserted into the database Before Update :  Trigger.new would be available containing the updated values Trigger.old would be available containing the old val

Webservice callout from Scheduled Apex

Making webservice callout from Schedulable classes Ever faced the error " System.CalloutException: Callout from scheduled Apex not supported. " This is the error you get when you are making a webservice callout from a class which is implementing Database.Schedulable interface. Salesforce does not allow you to make callouts from Schedulable classes. So I had this requirement where I needed to schedule a piece of code which was making a callout to external websrvice. This is my schedulable class : public class ExampleScheduler implements Schedulable{        public void execute(SchedulableContext SC) {       ExampleHelper.makeWebserviceCallout();    } } This is the class which contains webservice callout : public class ExampleHelper{ public static void makeWebserviceCallout(){ HttpRequest req = new HttpRequest(); req.setEndpoint('http://www.yahoo.com'); req.setMethod('GET'); String username = 'myname'; String password =

Update Converted Leads - Spring 16

With Spring 16 release, now you can update the converted leads. You need to do some user-specific and profile based settings and you are good to go. If you are a System Administrator, then you can even convert the lead which was already converted (seems to be a bug to me). Follow below steps to enable this feature : 1) From Setup, enter User Interface in the Quick Find box, then select User Interface. 2) Select Enable "Set Audit Fields upon Record Creation" and "Update Records with Inactive Owners" User Permissions. 3) Save your changes. 4) A4dd the setting to your profiles. From Setup, enter Profiles in the Quick Find box, then select Profiles. Select the profile and then select Set Audit Fields upon Record Creation. 5) Save your changes. If you want to update converted leads through dataloader, then you need to update a setting in Dataloader. Follow below steps to configure your dataloader: 1. In Data Loader, navigate to Settings -> Settings. 2. Upd

Clone with Related list

Image
The standard clone button provided by Salesforce does not have the capability to clone the related list records. So I thought of creating a custom button which will clone the parent record along with the related list records up-to one level deep. For example, you can clone Account with Contacts or Opportunities with Quotes or any standard or custom object. This app also provides you the ability to select which object's child records you want to clone. Code is uploaded @  GitHub Repo Follow below steps to make it working on your Salesforce org : 1) Copy the classes and VF page from GitHub to your Salesforce org. 2) Create a button named "Clone with Related List"  on the object you want to clone. I will take the example of Account. Behavior of the button should be "Execute JavaScript" and Content Source should be "OnClick JavaScript" 3) Copy below code for the button : {!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}  window.ope

Spring 16 - New features

Image
Spring 16 new features : Health Check : Do you know how secure your org is? Are you following the best security practices recommended by Salesforce? With the new Health check feature introduced in Spring 16, you can visually see how Salesforce has rated your org as per the current implementation present in it. If you are a security administrator, this tool will make your life much more easier. To check the health score, click on Setup and type Health check is the Quick Search Bar. Click on Health Check and a report is displayed which lists out the health score of your org and the potential risk factors. The risk factors are classified as : 1) High Risk Security Settings 2) Medium Risk Security Settings 3) Low Risk Security Settings Most of the security breaches are around the password requirements and password policies. Global Picklist :  Ever felt a need to share common picklist values across multiple objects? Tired of recreating the same picklist values on ev

Custom clone button in salesforce

Image
Custom clone button Ever faced a situation where you need to create a custom clone button. For example, you want to clone a lead record and you have a check-box on lead which you do not want to copy on the new record. In this article, we will see how to create a custom clone button. Use case : User wants to clone the lead record. There is a check-box on lead called "Data migrated record" whose value should not be copied. Step 1) Create a custom detail page button. Step 2) Put following url for the button created in step 1 : /{!Lead.Id}/e?clone=1&retURL=%2F{!Lead.Id}&00N9000000E9daG=false Let us analyse this url : a) {!Lead.Id} : Id of the original record from which new record has been cloned. b) clone=1 : url parameter which copies the value from original record to new record c) retURL=%2F{!Lead.Id} : specifies the page which should be opened when Cancel button is clicked d) 00N9000000E9daG=false : This is the id of check-box named "Data migra