Triggers – Helping to catch duplicates

Triggers – Helping to catch duplicates

Trigger
Triggers - Helping to catch duplicates. One way in which triggers can be of great help is by using them to catch duplicates records before insertion or before doing an update. Probably the easiest way to do this is by making sure you have implemented a unique key identifier on those records that you want to control and make sure that will not contain any duplicates. The unique identifier needs to be, well... 'unique', and no other record should contain that same key. Depending on the object in which you want to implement your "duplication preventer" you need to come up with that field that will contain your unique identifier. Let's take the Lead object for our test here, and I am going to use two unique values fields. Normally…
Read More
Dynamic Account Search

Dynamic Account Search

Center Blog
Dynamic Account Search I had a business requierment that was involving coding a controller in combination wiht a Visualforce page. The idea was to enable users to dynamically search for accounts. Looking for some ideas I found a really nice example from Jeff Douglas, you can find it here. So I took this structure and build my own page. The most interesting part of this code is the fact that you don't event need to click a "search" button to start retriving results. As nice as that can be there are other things that I really like about this code. The simplicity and efficiency of this code are really outstanding, that is why I want to share this with you, all credit goes to Jeff of course ... I'm just a messenger. This…
Read More
You got to love them, Maps ..

You got to love them, Maps ..

Apex
Maps vs For loops, Round 1 In this example I want to use a technique that will help us to avoid inserting for loops inside other for loops. Let's say you want to compare a couple of fields from different objects, in many situations you will find something similar to this: [code lang="php"] //SOQL queries to retrieve our values List<Lead> leadList = [SELECT Id, Email FROM Lead WHERE Email!= null]; List<Contact> contactList = [SELECT Id, Email FROM Contact WHERE Email != null]; for(Lead l: leadList) { for(Contact c: contactList) { if(l.Email == c.Email) { system.debug('There are emails matching: ' + 'Contact Email:' + c.Email + ' with Lead Email: ' + l.email); } } } [/code] If you run this code in an anonymous window it will run fine. The…
Read More
Wrapper Class

Wrapper Class

Apex
Wrapper Class A Wrapper Class is an extremely useful class that you can use when you need to group a number of objects in one "container". You will be using this class especially in Visualforce controllers. A more technical definition will be something like: "A wrapper or container class is a class, a data structure, or an abstract data type whose instances are collections of other objects" It is just a temporary container that can hold objects with their records for further calculations or logics within your code structure. We are going to build a table in a Visualforce page and display Contact and Account information in that same table using a wrapper class. Here is the initial class, class name WrapperDemoController and like you can see it contains on…
Read More
Triggers

Triggers

Trigger
They are, the triggers (Basics). As you probably know, triggers are one of the two Apex types we have to our disposal when developing with Apex. The most relevant difference between an Apex class and a trigger is the particular occasions in which triggers are used. They are related to DML, (Data Manipulation Language) operations. To keep it simple, when and execution operation fires actions like insert, update, delete, and undelete. These operations can be executed in a kind of "time frame"...nothing fancy, we can set the 'before' and 'after' attributes to our trigger to implicitly tell our trigger when to fire. An important factor when writing triggers is the fact that they run on system content, meaning this that there is not user reinforcement on access level or access…
Read More