Introduction to SalesForce Developer eXperience (SFDX)

Salesforce DX (SFDX) provides an integrated, end-to-end lifecycle designed for high-performance agile development.  It consists set of tools including Salesforce CLI, Second-Generation Packaging (2GP), Scratch Orgs,  VCS and CI support.

  1. Salesforce CLI

    The Salesforce CLI is a command line interface that simplifies development and build automation when working with Salesforce org. It can be used to;

    • Aggregate all the tools you need to develop with and perform commands against your Salesforce org
    • Synchronize source to and from scratch orgs
    • Create and manage orgs
    • Import and export data
    • Create and execute tests
    • Create and install packages
  2. Second-Generation Packaging (2GP)

    2GP allows create packages in a source-driven development environment. It can be used to create and deploy packages in own Salesforce org or to develop and distribute packages to customers. Here are some highlights of 2GP;

    • Salesforce command-line (CLI) support.
    • Options for enterprise customers to organize and deploy metadata to production orgs.Salesforce DX Logo
    • Multiple packages per namespace
    • Feature branch development and testing.
    • Fully API-driven functionality.
    • Packages that are source-driven, not org-based.
    • Ease of development and distribution of dependent packages.
  3. Scratch Orgs

    The scratch org is a source-driven and disposable deployment of Salesforce code and metadata. A scratch org is fully configurable, allowing developers to emulate different Salesforce editions with different features and preferences. And the scratch org configuration file can be shared with other team members.

String Manipulation in Salesforce #1

Salesforce provide set of methods for String manipulation. This article explains usage of each function with examples.

 

  1. Truncate strings with ellipses.
    abbreviate(maxWidth) returns a trimmed version of the String, of the specified length and with ellipses (…) appended if the current String is longer than the specified length; otherwise, returns the original String without ellipses.

    'Test Text Field'.abbreviate(8); //Test ...
  2. Convert to title case (Capitalize first letter)
    capitalize() capitalize first letter of the string.

    'test text field'.abbreviate(8); //Test text field
  3. Pad with Spaces (front & back)
    center(size) pads string with spaces in front and back while keeping String in the center.

    'test'.center(10); //    test
  4. Pad with Text (front & back)
    center(size, paddingString) pads string with specified text in front and back while keeping String in the center.

    'test'.center(10,'#'); //###test###
  5. Remove leading and trailing spaces
    trim() removes leading and trailing white spaces from the string.

    '   test    '.trim(); //test
  6. Escape characters.
    escapeCsv() – columns in CSV string enclosed with double quotes.
    escapeHtml3(), escapeHtml4() – escapes html characters in String.
    escapeJava() – escapes characters in String with Java rules. Characters escaped include quotes and control characters, such as tab, backslash, and carriage return characters.
    escapeSingleQuotes(stringToEscape) – escapes single quotes in String with backslash.
    escapeUnicode() – escapes Unicode characters.
    escapeXml() – escapes Xml tags in String.
  7. Convert first letter to lowercase
    uncapitalize() returns the String with the first letter in lowercase.

    'Test tTest Test'.uncapitalize(); //test tTest Test
  8. Convert to uppercase
    toUpperCase() Converts all of the characters in the String to uppercase using the rules of the default (English US) locale.

    'Test'.<code>toUpperCase</code>(); //TEST
  9. Convert to lowercase
    toUpperCase() Converts all of the characters in the String to uppercase using the rules of the default (English US) locale.

    'TesT'.<code>toLowerCase</code>(); //test
  10. Remove HTML tags
    stripHtmlTags() Removes all html tags from the String.

Loss of Fractions in Divisions

This is a small coding issue which can lead to serious calculation problems. When dividing numeric Integer or Long values, the fractional portion of the result, if any, is removed before performing any implicit conversions to a Double or Decimal.

Eg –

Double d = 5/3; // Expected result = 1.6666666666666667 | Actual result = 1.0

To eliminate this issue, values used for division must be converted to fractions before.

Double d = 5.0/3.0; // 1.6666666666666667

or

Double d = Double.valueOf(5)/Double.valueOf(3); // 1.6666666666666667