Dec 20, 2010

How Salesforce 18 Digit Id Is Calculated

Hi All,

As we know that each record Id represents a unique record within an organisation. There are two versions of every record Id in salesforce :

  • 15 digit case-sensitive version which is referenced in the UI
  • 18 digit case-insensitive version which is referenced through the API
The last 3 digits of the 18 digit ID are a checksum of the capitalizations of the first 15 characters, this ID length was created as a workaround to legacy systems which were not compatible with case-sensitive IDs.
The API will accept the 15 digit ID as input but will always return the 18 digit ID.

Now how we can calculate the 18 Digit Id from 15 Digit Id :

//Our 15 Digit Id
String id = '00570000001ZwTi' ;

string suffix = '';
integer flags;

for (integer i = 0; i < 3; i++) {
          flags = 0;
          for (integer j = 0; j < 5; j++) {
               string c = id.substring(i * 5 + j,i * 5 + j + 1);
               //Only add to flags if c is an uppercase letter:
               if (c.toUpperCase().equals(c) && c >= 'A' && c <= 'Z') {
                    flags = flags + (1 << j);
               }
          }
          if (flags <= 25) {
               suffix = suffix + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.substring(flags,flags+1);
          }else{
               suffix = suffix + '012345'.substring(flags-25,flags-24);
          }
     }

//18 Digit Id with checksum
System.debug(' ::::::: ' + id + suffix) ;


Thanks

Dec 6, 2010

Winter 11 Changes

Hi All,

Governor Limits

There are some good news with this winter 11 release, some governor limits are removed and some are increased like :

Removed Limits:

1) Total request time for one callout (HTTP request or web service call) has been removed.
2) Maximum size for a callout (HTTP request or Web service call) has been removed.

Increases to existing limits :

1) General heap size has been raised from 2 MB to 3 MB, with no scaling. In addition, batch Apex heap size is 6 MB.
2) Apex classes and triggers have been raised from 100,000 characters and 32,000 characters, respectively, and can now be one million characters long, not counting comments, test methode, and classes defined with @isTest.
3) Maximum ammount of Apex code allowed in an organisation has been raised from 1 MB to 2 MB.
4) Total number of ChildRelationship, RecordTypeInfo and PicklistEntry objects allowed and total number of fields calls allowed has been raised from 10 to 100.

Also in add on results of query in test class is increased from 500 to 10,000.

Visual Process Manager

Also with winter 11, you can now upload and manage business flows in salesforce.com. Visual process Manager, also known as Force.com Flow, and formerly known as Firefly, provides a robust business-friendly call scripting interface on the Force.com platform.

Apex Code Enhancements

1) isRunningTest method for system : Return true if the current executing code was called by code contained in a method defined as testMethod, false otherwise. Use this method if you need to run different code depending on whether it was being called from a test.

2) Void No Longer Accepted as Variable Type : Prior to winter 11, you could assign viod as a variable data type. While void is still an acceptable return type, you can no longer use it as a data type. For example, for all apex code saved using salesforce.com API version 20.0 or higher, the following is no longer valid :

Public class test
{
    Void v;
    Public void test(void arg1)
    {
    }
}


Custom Field Enhancements

Rich Text Area Field : There are two enhancements done in Rich Text Area in winter 11
1) Inline editing is now supported for richtext area field on detail page.
2) You can upload image to rich text area field from the salesforce.com API version 20 or later.

Thanks

Dec 4, 2010

Header Footer in PDF

Hi All,

It is about how we can put header and footer in a visual force page which is rendered as PDF.

<head>

<style>

@page {
    margin : 70pt .5in .5in .5in;
    @top-center {
        content : "My Header";
     }
    @bottom-left {
        content : "My Footer on Left Side";
        font-size : 10 px;
        color : #808080;
    }
    @bottom-center {
        content : "My Footer in center" ;
        font-size : 10 px;
        color : #808080;
    }
}

</style>

</head>

Now if we want to add a image in header then add:

@top-center {
        content : element(header);
     }

div.header {
    position : running(header) ;
}

in style and

<div class="header">
    <apex:image value="Image URL" />
</div>

before the body. We can also change font-size , font family , color etc of page using @page style.

Thanks