Tuesday, 2 September 2014

¡Que nos vamos a Dreamforce!

¡Este año me ha tocado! ¡Me voy a San Francisco en Octubre! Salesforce organiza una macro-conferencia los días del 13 al 16 de Octubre, llamada Dreamforce, ¡y este año sí que voy!

En los casi tres años que llevo trabajando para Desynit, he tenido la oportunidad de aprender un nuevo paradigma, la Nube, en particular la plataforma Salesforce, que ahora se llama Salesforce1. Durante este tiempo, he aprendido las diferencias entre un entorno local y un entorno distribuido en la Nube, así como las implicaciones que esto conlleva desde el punto de vista del desarrollador de aplicaciones y el diseño de soluciones.

Pues bien, en este tiempo he aprendido mucho, incluso me he certificado como desarrollador Force.com -Certified Force.com Developer-, y este año me ha llegado el momento tan deseado. Llevaba ya dos años viendo a los compañeros elegidos de Desynit para ir a San Francisco, siempre todos emocionados y flipando con la conferencia. Y cuando volvían, más de lo mismo, la verdad es que un poco de envidia sí que daba... Pues bien, este año nada de envidia, que este año ¡yo soy uno de los elegidos! Este año seré yo el que vuelva de San Francisco con la maleta cargada de camisetas, bolígrafos, libros y demás productos de Salesforce, entre otros...

Pero lo mejor de Dreamforce no son sólo las camisetas. La lista de expertos y personalidades que darán alguna charla es de lo más interesante, desde el propio fundador de Salesforce, Marc Benioff, hasta la antigua secretaria de estado de los EEUU, Hillary Clinton, pasando por cantantes y empresarios como Will.I.Am. Digo yo que esta gente tendrá algo interesante que contar, ¿no?

Además de esto, Dreamforce es un punto de encuentro de todos los profesionales que trabajan con Salesforce, ya sea en el ámbito de ventas, como de marketing o un ámbito más técnico. Todo el mundo está allí, y es una gran oportunidad para conocer a gente que se dedica a lo mismo que tú, con diferentes puntos de vista y distintas ideas.

En particular, Dreamforce es un evento en el que los desarrolladores reciben un tratamiento especial; no se les discrimina como en otras organizaciones, sino todo lo contrario. En Salesforce, el desarrollador está muy bien considerado, ya que es el perfil en el que se centra el éxito de la plataforma. Así que, que no se sorprenda nadie cuando descubra la "DevZone", un área de la conferencia expresamente reservada para desarrolladores, con sus propias charlas dedicadas, sus talleres en los que se puede practicar y demás. Es una zona en la que los desarrolladores se encuentran cómodos, porque está diseñada para eso.

En todas las ediciones de Dreamforce se desvelan los secretos mejores guardados del año, y se presentan todos los avances y mejoras que se introducen en la nueva versión de Salesforce. Pues bien, aquí es donde se puede hablar de todas las novedades, y de primera mano. Y lo mejor de todo, es que siempre te puedes poner manos a la obra para descubrirlo in situ, ya sea por ti mismo o acompañado por colegas o gente de las comunidades de Salesforce que por fin puedes llegar a conocer en persona.

Y además de todo esto, otra de las maravillas de este evento es que se desarrolla en San Francisco; un gran oportunidad para conocer la ciudad cuna del "Silicon Valley" y hacer un poco de turismo por sus míticas calles empinadas y su majestuoso puente "Golden Gate".

En fin, de momento esto es todo lo que puedo contar. Ya no queda nada para volar, y pronto estaremos de vuelta, así que ya escribiré otro artículo con la experiencia ya vivida.

Hasta entonces, diviértanse.

Thursday, 16 January 2014

Being a Certified Force.com Developer

Under the title of New year? - New Salesforce Certificate!, our first developer meetup of 2014 happened on the 8th of January at The Llandoger Trow pub, in Bristol (UK). The group meetups have been going on every other month since October 2012, giving developers around the South West of England the opportunity to gather and chat about Salesforce development.

The theme of the meetup in this occasion was Certification; at Desynit we have made our new years resolutions, and we are planning on getting our "Force.com Developer" and "Force.com Advanced Developer" certifications; hence the meetup.

Attendees chatting at the meetup
My colleague Simon created a really good presentation about getting Certified as a "Force.com Developer", in which I contributed with my own experience on preparing for the test and all the certification process. You can find a really good explanation of the Force.com Developer certification on his blog, from prices and training available to the duration of the test and format of the questions.

This is the presentation with all the slides we presented at the meetup.


Achieving the "Force.com Developer" certification was one of my objectives for the year after my annual review at Desynit, so I could get more involvement with Salesforce.com projects in the company.

When I took my "Force.com Developer" certification test I had been working on the platform for about 6 months. I had been developing on projects, involving object and field creation, some workflow and validation rules, some Visualforce and Apex triggers, and so forth. My experience had been with quite a few of the features of the Salesforce.com platform, having used both the point and click approach and some hands-on coding; this was enough to go for it.

The first thing I did as part of my preparation for the test was to go through the Force.com Workbook, which goes through the creation of a basic Warehouse application. By following this tutorial you are exposed to most of the aspects of the Salesforce.com platform; creation of an app, the required objects and fields, some business logic and some user interface customisation. It is a really good starting point as it explains the basics of the platform without going very deeply into details.

After the workbook I started the Force.com Fundamentals book, which is a much more in-depth guide to all of the features available in the Salesforce.com platform, and it is the main reference when it comes to the preparation of the "Force.com Developer" certification. This book also goes through the creation of an application, explaining all the steps in the process with a lot more details than the workbook. My main focus on this book was the Security and the Reporting sections, as they represent quite a big portion of the overall exam, and I hadn't had that much exposure to them on my day-to-day work.

Me presenting my slide
My last suggestion with regards to preparing for the "Force.com Developer" exam would be to have a look at the Study Guide, that can be found here, and gives a full outline of the exam and the weight of each section on the test. I would also recommend having a look at audit fields, multi-currency and encrypted fields, because these are not covered in the Fundamentals book and there are always a couple of questions about them in the exam.

After our presentation, my colleague Chris gave another presentation with his experience on getting the "Force.com Advanced Developer" certification, so if you are already a certified developer, have a look at his blog post and check what else it takes to become a "Force.com Advanced Developer", I'm already working on it, as I'm planning to get the Advanced certification by the end of the year.

If you are thinking about why we do this meetups and would like to join us, here are some of the reasons why you should join our Salesforce Developer User Group, so give it a go and sign up for the next event!
 

Wednesday, 4 December 2013

Auto-populate lookup fields in Salesforce

Have you ever tried to automatically populate a lookup field in Salesforce? If you have, you probably found no easy way of doing it. The first thought that might come to your mind is to create a workflow rule to update the lookup field, but that's not possible within Salesforce. That's why I decided to write this post entry with a breakdown of the approach we took.

THE PROBLEM

As part of my job at Desynit, I was asked for the option to auto-populate a lookup field with a specific value, depending on some condition being met on the parent record. I thought it would be easily achievable by means of the point and click approach of the Salesforce.com platform, but it turned out to be more complicated than I had initially anticipated.

THE ENVIRONMENT

In order to explain the scenario we were working on, I am going to use the standard Recruiting application that you can develop by following the Salesforce fundamentals developer guide, with some customisations.

The Recruiting app is a centralised application that can bring all of a company's recruiting and hiring processes together. This app tracks positions in all stages of the recruiting process (with a Position object); it will also track all of the candidates who apply for a particular position, including the status of their application (through the Candidate and Job Application objects); it will also allow employees to post reviews for candidates whom they've interviewed (via a Review object).

In general terms, this is the configuration of my environment:
  • Master-Detail relationship between the Job Application and the Review objects, being the Job Application the master object

  • Different record types for the Job Application object
  • A specific User profile ("IT Recruiter") for the "IT Position" Job Application record type
  • The Review object has a lookup field to a Supervisor (User object) for the review

THE REQUIREMENT

The requirement is for this lookup field in the Review object to be auto-populated in case the Job Application has a specific record type of "IT Position". Those reviews will always need to be supervised by the same User, so it is required to be auto-populated in order to avoid unwanted assignments. In this case, the User I will be using as a Supervisor is the Admin User of my org: "Julio Fernandez".

THE OPTIONS

The first option you can think of is creating a Workflow Rule to update the lookup field, and that's exactly what I first thought about when I faced this case. I would have ideally preferred having the capability of updating lookup fields in Salesforce, so I could apply a condition on the Review's Job Application parent and then an action to update my lookup field with the appropriate value.

However, updating lookup fields is still not allowed in Salesforce, so I had to find my head around this by any of the following options:

- I had the possibility of creating a new Visualforce page with a custom controller to extract the relevant information and fill in the appropriate fields before showing the create Review page

- Given the characteristics of this scenario, I thought about creating a new Page Layout for the "IT Recruiter" User profile so that the lookup field would be hidden and then create a new trigger to populate the lookup field; by doing it this way I just need to create a Trigger class (and its related test class), making use of the point and click feature of Salesforce to create the Page Layout for the affected User profile.

THE CHOSEN SOLUTION

My chosen option is the last one, because it leverages the point and click features of Salesforce to apply different Page Layouts to different profiles. It only requires creating new Trigger class to perform the auto-population, which means less custom elements in the system.

Now we all know the scenario in which we are working and the chosen solution, let's go for it and begin by creating the new page layout for the "IT Recruiter" profile.

THE NEW PAGE LAYOUT

Within the Review custom object definition, create a new Page Layout based on the default one, I called it "IT Recruiter Layout" and removed the Supervisor lookup field from the Layout; note that the Supervisor field is now in the editor palette, instead of being displayed within a section of the page.


This Page Layout will be assigned to the "IT Recruiter" User profile, so they cannot edit the Supervisor lookup field when creating a Review for the "IT Position" Job Applications.

THE NEW TRIGGER

Now it's time to code the Trigger class for the Review object. The change applied to the review records will be for the before insert and before update events on the records.

I will only take into account the Job Application's record type to evaluate whether the lookup field for the Supervisor needs to be populated, modified or untouched; and I will not make a difference on the User profile. This is because the requirement is that every time a Job Application has an "IT Position" record type, the Supervisor should be "Julio Fernandez", so in case a non "IT Recruiter" user specified a different value for the Supervisor, this value would be overwritten by the Trigger to take the required value of "Julio Fernandez".

The Trigger I have coded for the Review object will make use of a Utils class, so that the events are more readable in the Trigger class, as shown next:

The Utils class is defined next:

Please do not forget to include the Test class for your new classes, or your changes will not be able to be promoted to Production; I would always try and aim for 100% test coverage. Also bear in mind the new API of Salesforce does not include any of the existing data as part of your Test Runs, so you will have to create all your records when performing your tests.

CHECK WHAT WE'VE DONE

Bob Smith is a user on my org that belongs to the "IT Recruiter" profile. When this user tries to create a Review for an "IT Position" Job Application, the Page Layout will not show the Supervisor lookup field. Note in the following image that the logged in user is Bob Smith and the Supervisor lookup is not available to be edited:


Once the new record is saved we can view the affected Job Application; its Review related list will show the newly created Review, and the Supervisor field has been auto-populated with the required value of "Julio Fernandez".


I hope the example shown on this article was useful. Please leave your comments below and let me know if you find any bugs.

Tuesday, 8 October 2013

Java for Talend Tips

Talend provides data, application and business process integration solutions.

Ready for big data environments, Talend’s flexible architecture easily adapts to future IT platforms. Talend’s unified solutions portfolio includes data integration, data quality, master data management, enterprise service bus and business process management.

Talend offers a flexible open source based platform, delivered through an easy-to-use, Eclipse-based graphical environment that provides a comfortable workbench for developers.

Talend is based on Java, and the designs you create generate Java code; but its graphical interface provides great power to the developer with no need to hand code.

However, there are situations in which you cannot avoid adding some customised handling to your Data, mainly related to transformations of your Data Types like Strings, Dates, Integers and so forth.

Those of you who do not have knowledge of Java, please do not be scared to learn a few of the basic Java features shown next that will help you optimise your use of Talend:

When To Use Your Customisations


The main components for which you will find it useful to apply your own customisations are the Mapping components, like tMap or tXMLMap, , and the Java components, like tJava, tJavaFlex or tJavaRow.
  • In the Mapping components you will be able to use expressions and methods within expressions to manipulate the fields and apply transformations for your data: An expression is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value. This is the very important: an expression evaluates to a single value.

  • In the Java components you will be able to use not only expressions and methods within the expressions, but also assignments and more in-depth functionality like blocks and loops, but this is not very frequently required: Statements are roughly equivalent to sentences in natural languages. A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon (;)
    • Assingment expressions
    • Any use of ++ or --
    • Method invocations
    • Object creation expressions

Primitive Data Types


A variable's data type determines the values it may contain, plus the operations that may be performed on it. The eight primitive data types supported by the Java programming language are:
 
byte: An 8-bit signed two's complement integer. Min value: -128, Max value: 127 (inclusive).

short: A 16-bit signed two's complement integer. Min value: -32,768, Max value: 32,767 (inclusive).


int: A 32-bit signed two's complement integer. Min value: -2,147,483,648, Max value: 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice and it will most likely be large enough for the numbers you will use, but if you need a wider range of values, use long instead.
 

long: A 64-bit signed two's complement integer. Min value: -9,223,372,036,854,775,808, Max value: 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int.
 

float: A single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but can be found here. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead.

double: A double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion
, but can be found here. For decimal values, this data type is generally the default choice, but it should never be used for precise values, such as currency.
 

boolean: It has only two possible values: true and false. Use this data type for simple flags that track true/false conditions.

char: A single 16-bit Unicode character. Min value: '\u0000' (or 0), Max value: '\uffff' (or 65,535 inclusive).


Apart from these eight primitive types, the Java programming language also provides special support for character strings via the java.lang.String class. Enclosing your character string within double quotes will automatically create a new String object; for example, String s = "this is a string";. The String class is not technically a primitive data type, but considering the special support given to it by the language, you'll probably tend to think of it as such.

Java Operators


Simple Assignment operator: the most common operator is "=", it assigns the value on its right to the operand on its left: int myNumber = 2;

Arithmetic operators:
  • Additive operator: + (also used for String concatenation)
    int result = 1 + 2; // result is 3 
  • Subtraction operator: -
    int result = 3 - 1; // result is 2
  • Multiplication operator: *
    int result = 2 * 5; // result is10
  • Division operator: /
    int result = 9 / 3; // result is 3
  • Remainder operator: % (divides one operand by another and returns the remainder as its result)
    int result = 10 % 3; // result is 1
Unary operators:
  • Unary plus operator: + (indicates positive value)
    int result = +2; // result is 2
  • Unary minus operator: - (negates an expression)
    int result = +2; // result is 2
    result = -result; // result is -2
  • Increment operator: ++ (increments a value by 1)
    int result = +2; // result is 2
    result = result++; // result is 3
  • Decrement operator: -- (decrements a value by 1)
    int result = +2; // result is 2
    result = result--; // result is 1
  • Logical complement operator: ! (inverts the value of a boolean)
    boolean result = true; // result is true
    result = !result; // result is false
Equality and relational operators:
int a = 2;
int b = 2;

  • Equal to: ==
    boolean result = a == b; // result is true
  • Not equal to: !=
    boolean result = a != b; // result is false
  • Greater than: >
    boolean result = a > b; // result is false
  • Greater than or equal to: >=
    boolean result = a >= b; // result is true
  • Less than: <
    boolean result = a < b; // result is false
  • Less than or equal to: <=
    boolean result = b <= a; // result is true
Conditional operators:
int a = 1;
int b = 2;

  • Conditional AND: &&
    boolean result = (a == 1) && (b == 2); // result is true
    boolean result = (a == 2) && (b == 2); // result is false
    boolean result = (a == 1) && (b == 1); // result is false
    boolean result = (a == 3) && (b == 3); // result is false
  • Conditional OR: ||
    boolean result = (a == 1) || (b == 2); // result is true
    boolean
    result =
    (a == 2) || (b == 1); // result is false
    boolean result = (a == 2) || (b == 2); // result is true
  • Ternary Operator: ? : (this operator should be read as: "If someCondition is true, assign the value of value1 to result. Otherwise, assign the value of value2 to result.")
    int value1 = 1;
    int value2 = 2;
    int result;
    boolean someCondition = true;
    result = someCondition ? value1 : value2; // result is 1
The ternary operator is one of the most useful operators in the case of the Talend customisations as it allows you to include if-then-else processing to your expressions, and this is really helpful when processing your data in the Expression Builder for the Mapping components.

Talend Routines

Talend System Routines

The Talend platform offers some out-of-the-box routines with very useful functionality. You can access their definition from the Repository tab of Eclipse, under the Code section, providing specific methods for the following:
  • DataOperation
  • Mathematical
  • Numeric
  • Relational
  • StringHandling
  • TalendDataGenerator
  • TalendDate
  • TalendString 

All of these routines provide methods to help you calculate trigonometric cosines of expressions, transform a String to upper or lower case, amongst others, but the routine I found most helpful of all of them is the TalendDate one, because it considerably simplifies the transformations of Date fields into Strings and vice-verse, as well as offering methods to retrieve the current date or add time to a specified Date.

- Say you have a Date object "myDate" that represents the 2nd of May of 2006 and you wanted to display it with a String formatted as "dd/MM/yyyy". You can achieve this by using the formatDate method in the TalendDate routine:

     String theDate = TalendDate.formatDate("dd/MM/yyyy",myDate);
     // theDate is assigned the value "02/05/2006"

- If you wanted to build a Date object from a String that represents a date and time like "02/05/2006 13:35" you can use the parseDate method in the TalendDate routine:

     String aDate = "02/05/2006 13:35";
     Date theDate = TalendDate.parseDate("dd/MM/yyyy HH:mm",aDate);
     // theDate is a Date object representing the 2nd of May of 2006 at 13:35

This Java docs for the java.text.SimpleDateFormat class show lots of mask combinations you can use to produce and format your dates and times as required. 

The String Java Class And Its Methods


Out of the number of classes and libraries offered by Java, the most relevant for your Talend customisations is the java.lang.String class, and you will find it very useful because it offers great power to transform and manipulate your data.

Strings are a sequence of characters, and in the Java programming language they are objects. The Java platform provides the java.lang.String class to create and manipulate strings; some of this class's features are shown next:

How to create Strings

The class provides thirteen constructors that let you specify the initial value for the String using different sources, like:

     String greeting = "Hello world!";
     String newGreet = new String("Hello world!");
     String charGreet = new String({'H','e','l','l','o','!'});


How to concatenate Strings

The String class includes a method for concatenating strings, which returns a new string that is the result of adding the second string to the first one; but the + operator is frequently used to perform string concatenations, for example:

     String string1 = "Hello ";
     String
string2 = new String("world!");
     String string3 = string1.concat(string2);
     String string4 = "Hello ".concat("world!");
     String string5 = string1 + "world" + "!";
     StringBuilder string6 = new StringBuilder(string1);
     string6.append(string2);
     // string3, string4, string5 and string6 are "Hello world!"

Any object that is not a String can also be transformed into a String via their toString() method, which returns a representation of the object in the form a String, so they can also be concatenated to other strings.

Your code can benefit from the use of the StringBuilder class, as it doesn't create a new instance of a String every time you concatenate, so your code will be optimised.

 How to compare Strings

A number of methods are available within the String class for comparing strings and portions of strings, which are really useful when you need to check the values for your data; some of them are:

boolean endsWith(String suffix) / boolean startsWith(String prefix): These methods return true if this string ends with or starts with the substring specified as an argument to the method.

     String something = "Hello";
     boolean end = something.endsWith("lo");
     boolean ini = something.startsWith(" He");
     // end is true and ini is false

boolean equals(Object anObject) / boolean equalsIgnoreCase(String aString): The returned value is true if and only if the argument is a String object that represents the same sequence of characters as this object, ignoring the difference in case for equalsIgnoreCase.

     String something = "Hello";
     boolean isEqual = something.equals("Hello");
     boolean isEqualIgnore = something.equalsIgnoreCase("hello");
     // in both cases the result is true

boolean matches(String regex): This method test whether this string matches the specified regular expression, very useful to check formats of strings, like checking for valid emails or certain date formats.
 
     String validEmail = "me@mycompany.com";
     String wrongEmail = "me@my company.com";
     String regex = "[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})";
     boolean valid = validEmail.matches(regex);
     boolean wrong = wrongEmail.matches(regex);
     // valid is true and wrong is false

How to compare between Numbers and Strings

The Java platform provides a set of Number subclasses that wrap the primitive numeric types to provide further functionality, like Byte, Integer, Double, Float, Long and Short.

Converting Strings to Numbers: These wrapping Number classes include a method called valueOf, that converts a string to an object of that type; they also provide a parseXXXX() method, like parseDouble(), that converts strings to primitive type, instead of the wrapping objet:

     String aNumber = "0.2";
     Float aFloatObject = Float.valueOf(aNumber);
     // valueOf returns a Float object
     float aFloat = Float.parseFloat(aNumber);
     // parseFloat returns a primitive type variable

Converting Numbers to Strings: The String class provides a method called valueOf that performs the transformation of the Number subclasses objects into strings; at the same time, each of the Number subclasses has a toString() method that returns the string value of the object; and again the + operator can be used to concatenate a number and the transformation is automatically handled by Java:

     int anInt = 987;
     String intValueOf = String.valueOf(anInt);
     // intValueOf is "987"

     int anotherInt = 3002;
     double aDouble = 858.48;
     String anIntString = Float.toString(anotherInt);
     String aDoubleString = Double.toString(aNumber);
     // anIntString is "3002" and aDoubleString is "858.48"
  
     int lastInt = 23;
     String intToString = "" + lastInt;
     // intToString is "23" 

Other useful Methods for handling Strings

Here is a list of some other useful methods available in the String class for changing case, finding characters or substrings within a string amongst others:

String trim(): This method returns a copy of the string with leading and trailing white space removed.

String toLowerCase() / String toUpperCase(): These methods return a copy of the string converted to lowercase or uppercase.

String substring(int beginIndx) / String substring(int beginIndx, int endIndx): These methods return a new string that is a substring of this string, from the character in position beginIndx to the end of the original string or from the character in position beginIndx to the character in position endIndx - 1.

int indexOf(String str) / int lastIndexOf(String str): These methods return the index of the first / last occurrence of the string specified as argument if it is found or -1 if not found.

String replace(CharSequence target, CharSequence replacement): This method returns a copy of the string after replacing each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

String replaceAll(String regex, String replacement): This method returns a copy of the string after replacing each substring of this string that matches the given regex with the specified replacement.

int length(): This method returns the number of characters contained in the string object.

This is it for the time being, if you have any suggestions or doubts, please do not hesitate to leave a comment below. Many thanks.

This article has used references from the Java Basics page.