Posts

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 v...

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 ...

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 o...

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...

ActionFunction and ActionSupport in Salesforce - When to use what?

Most of the newbies in Salesforce are confused regarding the usage of <apex:actionSupport> and <apex:actionFunction> tags. Lets take a brief overview about what they are and when to use what. <apex:actionSupport> - This component is used when you want to provide AJAX support to a another component. For example, on click of an image , we need to call an apex function. So, in between start tag and end tag of our image, we can put an action support component. We need to specify the javascript event, for example onclick event and the apex action which needs  to be called when this event happens.  <apex:page controller="ActionController">   <apex:form >       <apex:image url="https://login.salesforce.com/img/logo190.png">           <apex:actionSupport action="{!methodInApex}" event="onclick"/>       </apex:image>   </apex:form> </apex:page> ...