Category: Sample codes

  • Salesforce: Adding specific working days to a Date

    UPDATE: If you want to consider holidays and business hours you can check out this article.

    Many time while coding we come across the requirement in which we need to calculate the EndDate from a StartDate after a specific number of business/working days. That means excluding the weekends (Saturday & Sunday) Following is the code snippet which does this. I know there can be an optimized way of doing this. But I didn’t want to spend more time on this.

    Below method takes date and number of working days to be added to the date.

    https://gist.github.com/prasannadeshpande/b56d3d78fb461fa7b27e5462e7543ac4

    Method daysOff calculates the number of non-working days coming in the start date and end date. And after which we are again adding those number of days.

  • Showing the Processing/Loading image

    I came across a good code sample while surfing for showing the Loading/Processing  image on the VisualForce Page.

    You can find it at: http://force.siddheshkabe.co.in/2009/10/displaying-please-wait-ajax-animation.html

  • Regex for AlphaNumeric password validation

    Regular Expression for validating the string

    (?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,20})$

    The above RegEx requires at least one digit and at least one alphabetic character. It does not allow special characters. The length must be from 8 to 20 characters.