Generic Loading Component For Visualforce Pages

Visualforce Page Component:

<apex:component>
    <apex:actionStatus onstart="startLoading();" onstop="stopLoading();" id="loadStatus" />
    <style>
        .overlay {
            display: none;
            height: 100%;
            left: 0;
            position: fixed;
            top: 0;
            opacity: 0.3;
            -moz-opacity: 0.3;
            width: 100%;
            -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
            filter: alpha(opacity=30);
            background: #000;
            -khtml-opacity: 0.3;
            z-index: 1000;
        }

        .loader {
            background: url('/img/loading32.gif') scroll no-repeat 0 0;
            width: 32px;
            height: 32px;
            position: absolute;
            left: 50%;
        }
    </style>

    <div id="load_scrl" class="loadingBox loader" style="display:none"> </div>
    <div class="loadingBox overlay"> </div>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">

        function startLoading() {
            $('#load_scrl').css('top', $(document).scrollTop() + 200);
            $('.loadingBox').show();
        }

        function stopLoading() {
            $('.loadingBox').hide();
        }
    </script>
</apex:component>

Now add this component in your Visualforce Page:

<c:LoadingIcon/>

Use the “Status” attribute with the value “loadStatus” on the command button as follows:

<apex:commandButton action="{!save}" value="Save" status="loadStatus" rerender="myForm"/>

Use in Javascript:

startLoading(); //Start Loading
stopLoading() ; //Stop Loading

Javascript Function For Validation on Number,Letters and Currency Input Fields

<script type="text/javascript">
    // This function is being used for providing different validation on your text box as per your need
    function ValidatedField(e, allow) {

        var AllowableCharacters = '';

        if (allow == 'Letters') {
            AllowableCharacters = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
        }
        if (allow == 'Numbers') {
            AllowableCharacters = '1234567890';
        }
        if (allow == 'NameCharacters') {
            AllowableCharacters = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.\'';
        }
        if (allow == 'NameCharactersAndNumbers') {
            AllowableCharacters = '1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-\'';
        }
        if (allow == 'Currency') {
            AllowableCharacters = '1234567890.';
        }

        var k = document.all ? parseInt(e.keyCode) : parseInt(e.which);

        if (k != 13 && k != 8 && k != 0) {
            if ((e.ctrlKey == false) && (e.altKey == false)) {
                return (AllowableCharacters.indexOf(String.fromCharCode(k)) != -1);
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
</script>

Get The Week Number of Month From Date in Salesforce

public Integer weekOfMonth(Date todaysDate){
        Integer weekCount = 0;
        Integer startWeekResidue = 0;
        Integer endWeekResidue = 0;
        
        //Calculating startWeekResidue
        Date dt = todaysDate.toStartOfMonth().addDays(-1);
        Date dtFirstWeekend = dt.toStartOfWeek().addDays(6);
        startWeekResidue = dt.daysBetween(dtFirstWeekend);
        
        //Calculating endWeekResidue
        Date dtLastWeekend = todaysDate.toStartOfWeek().addDays(-1);
        endWeekResidue = dtLastWeekend.daysBetween(todaysDate);
        
        //Counting the weeks
        weekCount = (todaysDate.day() - (startWeekResidue + endWeekResidue))/7;
        weekCount += (startWeekResidue > 0 ? 1:0)+(endWeekResidue > 0 ? 1:0);
        System.Debug('Week Number: ' + weekCount);
        return weekCount;
}

Example: Pass Parameter: 13Sept2017 – Output: 3

Salesforce Object Key Prefix List

Every ID in Salesforce is either 15 characters or 18 characters (API). The first 3-digits of the ID are always the Entity ID which can be used to determine the type of the entity.

For example, an Account record with ID “001D000000IBVzo” has the prefix “001” on NA1 which has server ID ‘D0’:

Below is the Object Key Prefix List:

Object Type Key Prefix
ACCOUNT ‘001’
QUOTE ‘0Q0’
NOTE ‘002’
CONTACT ‘003’
USERS ‘005’
OPPORTUNITY ‘006’
ACTIVITY ‘007’
OPPORTUNITY_HISTORY ‘008’
FORECAST_ITEM ’00A’
FILTER ’00B’
DELETE_EVENT ’00C’
ORGANIZATION ’00D’
USER_ROLE ’00E’
QUEUE ’00G’
GROUPS ’00G’
PARTNER ’00I’
OPPORTUNITY_COMPETITOR ’00J’
OPPORTUNITY_CONTACT_ROLE ’00K’
CUSTOM_FIELD_DEFINITION ’00N’
REPORT ’00O’
ATTACHMENT ’00P’
LEAD ’00Q’
IMPORT_QUEUE ’00S’
TASK ’00T’
EVENT ’00U’
EMAIL_TEMPLATE ’00X’
EMAIL_TEMP ’00Y’
COMMENTS ’00a’
CUSTOM_RESOURCE_LINK ’00b’
TRAINING ’00c’
PROFILE ’00e’
MH_BLUESHEET ’00f’
MH_GOLDSHEET ’00g’
LAYOUT ’00h’
PRICEBOOK_MAPPING ’00i’
PRICEBOOK_ENTRY_MAPPING ’00j’
OPPORTUNITY_LINEITEM ’00k’
FOLDER ’00l’
EMAIL_ATTACHMENT_LOOKUP ’00m’
EMAIL_ATTACHMENT_ARCHIVE ’00n’
LINEITEM_SCHEDULE ’00o’
USER_TEAM_MEMBER ’00p’
OPP_TEAM_MEMBER ’00q’
ACC_SHARE ’00r’
ACC_SHARE_DEFAULT ’00s’
OPP_SHARE ’00t’
OPP_SHARE_DEFAULT ’00u’
CAMPAIGN_MEMBER ’00v’
PAYMENT_APPLICATION ’00w’
BILLED_PRODUCT ’00x’
PURCHASE_RULE ’00y’
PURCHASE_RULE_ENTRY ’00z’
CASE_SOLUTION ‘010’
GROUP_MEMBER ‘011’
RECORD_TYPE ‘012’
RECORD_TYPE_PICKLIST ‘013’
PROFILE_RECORD_TYPE ‘014’
DOCUMENT ‘015’
BRAND_TEMPLATE ‘016’
ENTITY_HISTORY ‘017’
EMAIL_STATUS ‘018’
BUSINESS_PROCESS ‘019’
BUSINESS_PROCESS_PICKLIST ’01A’
LAYOUT_SECTION ’01B’
LAYOUT_ITEM ’01C’
PROFILE_LAYOUT ’01G’
MAILMERGE_TEMPLATE ’01H’
CUSTOM_ENTITY_DEFINITION ’01I’
PICKLIST_MASTER ’01J’
CURRENCY_TYPE ’01L’
ACC_TEAM_MEMBER ’01M’
ACTIVE_CONTENT ’01N’
USER_UI_CONFIGURATION ’01O’
PROFILE_TAB_CONFIGURATION ’01P’
WORKFLOW_RULE ’01Q’
RULE_FILTER ’01R’
RULE_FILTER_ITEM ’01S’
RULE_FILTER_ACTION ’01T’
ACTION_ASSIGN_ESCALATE ’01U’
ACTION_TASK ’01V’
ACTION_EMAIL ’01W’
ACTION_EMAIL_RECIPIENT ’01X’
CAMPAIGN_MEMBER_STATUS ’01Y’
DASHBOARD ’01Z’
DASHBOARD_COMPONENT ’01a’
FILTER_ITEM ’01b’
FILTER_COLUMN ’01c’
FOLDER_GROUPS ’01d’
PICKLIST_SET ’01e’
WEBEX_MEETING ’01f’
API_QUERY ’01g’
TRANSLATION ’01h’
TRANSLATION_USER ’01i’
TRANSLATION_VALUE ’01j’
PROFILE_FLS_ITEM ’01k’
ACTION_RESPONSE ’01l’
BUSINESS_HOURS ’01m’
CASE_SHARE ’01n’
LEAD_SHARE ’01o’
CUSTOM_TAB_DEFINITION ’01r’
PRICEBOOK2 ’01s’
PRODUCT2 ’01t’
PRICEBOOK_ENTRY ’01u’
PRICEBOOK_SHARE ’01v’
OPP_UPDATE_REMINDER ’01w’
OPP_UPDATE_REMINDER_STATS ’01x’
CASE_SHARE_DEFAULT ’01y’
CASE_ESCALATION ’01z’
EVENT_ATTENDEE ‘020’
QUANTITY_FORECAST ‘021’
FISCAL_YEAR_SETTINGS ‘022’
APP_CALENDAR ‘023’
APP_CALENDAR_SHARING ‘024’
LIST_LAYOUT_ITEM ‘025’
PERIOD ‘026’
REVENUE_FORECAST ‘027’
OPPORTUNITY_OVERRIDE ‘028’
LINEITEM_OVERRIDE ‘029’
LEAD_SHARE_DEFAULT ’02A’
LABEL_DEFINITION ’02B’
LABEL_DATA ’02C’
CASES_HISTORY2 ’02D’
HELP_SETTING ’02E’
CUSTOM_FIELD_MAP ’02F’
MH_GOLD_PROGRAM ’02H’
MH_GOLD_INFORMATION ’02I’
MH_GOLD_CONTACT ’02J’
MH_GOLD_ACTION ’02K’
MH_CUSTOMER_CRITERION ’02L’
MH_GREENSHEET ’02M’
MH_GREEN_GIVE_INFO ’02N’
MH_GREEN_GET_INFO ’02O’
MH_CONTACT_ROLE ’02P’
MH_INFORMATION ’02Q’
USER_PREFERENCE ’02R’
HTML_COMPONENT ’02S’
CUSTOM_PAGE ’02T’
CUSTOM_PAGE_ITEM ’02U’
PAGE_COMPONENT ’02V’
CUSTOM_PAGE_PROFILE ’02X’
USER_COMPONENT_DATA ’02Y’
ACCOUNT_CONTACT_ROLE ’02Z’
CONTRACT_CONTACT_ROLE ’02a’
COMPONENT_RESOURCE_LINK ’02b’
DIVISION ’02d’
DIVISION_WORKFLOW_RULE ’02e’
DELEGATE_GROUP ’02f’
DELEGATE_GROUP_MEMBER ’02g’
DELEGATE_GROUP_GRANT ’02h’
ASSET ’02i’
PROFILE_ENTITY_PERMISSIONS ’02j’
LIST_LAYOUT ’02k’
OUTBOUND_QUEUE ’02l’
CUSTOM_INDEX ’02m’
CATEGORY_NODE ’02n’
CATEGORY_DATA ’02o’
DIV_TRANSFER_EVENT ’02p’
LAYOUT_ITEM_COLUMN ’02q’
OPPORTUNITY_ALERT ’02r’
EMAIL_MESSAGE ’02s’
EMAIL_ROUTING_ADDRESS ’02t’
TAB_SET ’02u’
TAB_SET_MEMBER ’02v’
LOGIN_IP_RANGE ’02w’
LOGIN_HOURS ’02x’
REPORT_AGGREGATE ’02y’
REPORT_COLOR_RANGE ’02z’
PROFILE_TAB_SET ‘030’
USER_TAB_SET_MEMBER ‘031’
ACC_TERRITORY_RULE ‘032’
PROJECT ‘033’
PROJECT_MEMBER ‘034’
SELF_SERVICE_USER ‘035’
JOB_QUEUE ‘036’
REPORT_COLUMN ‘037’
REPORT_FILTER_ITEM ‘038’
REPORT_BREAK ‘039’
DEPENDENT_PICKLIST ’03a’
PACKAGE_EXPORT ’03b’
LAYOUT_RIGHT_PANEL ’03c’
CUSTOM_SETUP_DEFINITION ’03e’
CUSTOM_SETUP ’03f’
REPORT_PARAM ‘040’
ACC_TERRITORY_ASSIGN ‘041’
ACC_TERR_ASSIGN_RULE_ITEM ‘042’
OUTBOUND_FIELD ‘043’
USER_TERRITORY ’04S’
TERRITORY ’04T’
DNB_ACCOUNT_MAPPING ’04U’
DNB_FIELD ’04V’
REVENUE_FORECAST_HISTORY ’04W’
QUANTITY_FORECAST_HISTORY ’04X’
CONTENTVERSION ‘068’
CONTENTDOCUMENT ‘069’
ENTITY_PERMISSION ‘110’
SFDC_PARTNER ‘204’
SFDC_DIVISION ‘208’
CASES ‘500’
SOLUTION ‘501’
BILLING_DIVISION 600′
BILLING_ORDER 601′
CURRENCY 602′
PLAN 604′
PRODUCT ‘605’
BILLING_ORDER_ITEM ‘606’
PLAN_PRODUCT ‘607’
CAMPAIGN ‘701’
FIELD_HISTORY ‘737’
UI_STYLE_DEFINITION ‘766’
UI_STYLE ‘777’
CONTRACT ‘800’
ORDERS ‘801’
ORDER_ITEM ‘802’
INVOICE ‘803’
INVOICE_ITEM ‘804’
PAYMENT ‘805’
APPROVAL ‘806’
URI_BLOCK_RULE ‘807’
CUSTOM_ENTITY_DATA ‘a00’
SERVICECONTRACT ‘810’
USERLICENSE ‘100’
CUSTOM_LABEL ‘101’
APEXCLASSMEMBER ‘400’
FORECASTSHARE ‘608’
ASYNCAPEXJOB ‘707’
APEXTESTQUEUEITEM ‘709’
BULK_QUERY_JOB ‘750’
BULK_QUERY_BATCH ‘751’
BULK_QUERY_RESULT ‘752’
REMOTE_ACCESS ‘888’
EMPTYKEY ‘000’
USERACCOUNTTEAMMEMBER ’01D’
APEXCLASS ’01p’
APEXTRIGGER ’01q’
SHARINGRULE ’02c’
VALIDATIONRULE ’03d’
QUEUESOBJECT ’03g’
CASECONTACTROLE ’03j’
CONTACTSHARE ’03s’
USERPERFERENCE ’03u’
PROCESSINSTANCE ’04g’
PROCESSINSTANCESTEP ’04h’
PROECESSINSTANCEWORKITEM ’04i’
OUTBOUND_MESSAGE_ID ’04k’
OUTBOUND_NOTIFICATION_ID ’04l’
ADDITIONALNUMBER ’04m’
ASYNCRESULT ’04s’
INSTALL_PACKAGE ’04t’
CALLCENTER ’04v’
FIELD_UPDATE ’04Y’
CONTENTWORKSPACE ‘058’
CONTENTWORKSPACEDOC ‘059’
DOCUMENTATTACHMENTMAP ’05X’
PORTAL_ID ‘060’
APEXPAGE ‘066’
SANDBOX ’07E’
APEXLOG ’07L’
APEXTESTRESULT ’07M’
STATICRESOURCE ‘081’
DATA_FROM_UNINSTALLED_PACKAGES ‘082’
VOTE ‘083’
IDEA ‘087’
CRONTRIGGER ’08e’
CAMPAIGNSHARE ’08s’
EMAILSERVICESFUNCTION ‘091’
WEEKLY_DATA_EXPORT ‘092’
EMAILSERVICEADDRESS ‘093’
APEXCOMPONENT ‘099’
COMMUNITY ’09a’
CHANGE_SET ‘0A2’
INSTALLED_PACKAGE ‘0A3’
CONNECTION_S2S ‘0BM’
HOLIDAY ‘0C0’
ORGWIDEEMAILADDRESS ‘0D2’
USERPROFLEFEED ‘0D5’
SITE ‘0DM’
ENTITYSUBSCRIPTION ‘0E8’
INBOUND_CHANGE_SET ‘0EP’
SETUPENTITYACCESS ‘0J0’
PERMISSION_SET_METADATA ‘0PS’
TAGDEFINITION ‘0t0’
LOGINHISTORY ‘0Ya’
METADATACONTAINER ‘1dc’
CONTAINERASYNCREQUEST ‘1dr’
TRACEFLAG ‘7tf’

Note: This list is not updated with every release.

Find Object Type From Record ID Prefix

Standard and Custom Objects in Salesforce have three character prefixes which form the first part of the record ID. For example, an Account record with ID “001g000001jmmCA” has the prefix “001”, which is the prefix for the Account object.

In some scenarios, you may want to find out the name of the object associated with the prefix using Apex code.

Find the Object name based on Record ID prefix:

String objectName = SchemaGlobalDescribe.findObjectNameFromRecordIdPrefix('100');
System.debug('Object Name: '+ objectName);

Find the Object name based on record ID:

Id recordId = '001g000001jmmCA';
System.debug('Object Name: '+ recordId.getsobjecttype());