Showing posts with label VisualForce. Show all posts
Showing posts with label VisualForce. Show all posts

Monday 30 September 2013

REGEX in Salesforce

13:00
What is a RegEx?

Regular Expression in computing terms is a pattern that is used to search. It has its own syntax and semantics. To learn more on what RegEx is visit --> here
Great now we learnt what REGEX is, to build your own regex visit --> buildregex.com

So how does all this play in salesforce apex ? There are numerous use cases for using regex and checking patterns e.g. Checking if string is in Email Format.

There are 2 Major Classes to check if regex matches. Pattern Class and Matcher Class
in short, the pattern class is used to store a type of regex and once you have a pattern stored, We use the Matcher Class to identify if a specified string matches the pattern.

Here's the code for Matching String to Email pattern In salesforce

public static Boolean checkEmailFormat(String email) {
        String emailRegEx = '[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\*\\/\\=\\?\\^\\_\\+\\-\\`\\{\\|\\}\\~\'._%+-]+@[a-zA-Z0-9\\-.-]+\\.[a-zA-Z]+';
        Pattern MyPattern = Pattern.compile(emailRegex);
        Matcher MyMatcher = MyPattern.matcher(email);
        Boolean result = MyMatcher.matches();
        return result;
    }

This is a self explanatory code, the Pattern is first compiled and stored, then we check the "email" parameter matches the regex, the result (true/false) is returned to the calling method. Wanna learn more ? --> Check SFDC Documentation

Hope this helped  ! Let me know your thoughts or if there are some neat regex that you'd like to share in the comments . Happy Coding !

Wednesday 11 September 2013

Email Case Team Members on Case Comment

14:40

This is going to be a short blog for a requirement I came across, But didn't find any blogs out there addressing this. So lets get right to it, I need to notify all the case team members when a case comment is logged, be it contact, users etc.


Here's what we'll need


  • Trigger on Case Comment 
  • A Helper Class (To keep the trigger clean)
  • Test Class ( Don't forget to test your code)
To make things look clean we'll keep most of the code to the helper class,

Saturday 11 May 2013

<apex:actionStatus>

03:10
Action status is usually used to show the status of an Ajax Process to which it is related to. It can be as simple as showing text during the update to as fancy as greying out the page and showing a loading gif. your imagination (and HTML CSS skills) are the limits

Thursday 14 March 2013

Visualforce To Excel

02:11
In this short post I want to explain how we can generate an excel output from a VF page.  We already know to how to generate a PDF from VF page. (Read more to find out how). One of the common requirements is to convert a VF page with data into an Excel sheet, here are some things you may want to keep in mind
  1. Use a separate VF page for export. It is advisable to use a separate VF page to export off, reason being, usually the VF page in which data resides contains buttons, links images etc. and that is not something you usually want in your excel
  2. Use <apex:dataTable> : this gives you a consistent output and works for both windows and MAC. (Thank you Pratyush Kumar  for the Info)
  3. Proper validation : Before the export page is reached, make sure all validations to ensure data will be present is  a good practice