Tag Archives: SFDC

PHP Function to Calculate the Salesforce 15 Character ID to 18 Charachter ID

function salesForceIdCalculate($id)
{
    $map      = implode('', array_merge(range('A', 'Z'), range(0, 9)));
    $checksum = '';
    
    foreach (str_split($id, 5) as $chunk) {
        $checksum .= substr($map, bindec(strrev(array_reduce(str_split($chunk, 1), function($carry, $item)
        {
            $carry .= (!is_numeric($item) && $item == strtoupper($item)) ? '1' : '0';
            return $carry;
        }, ''))), 1);
    }
    
    return $checksum;
}

// example
//$_15ID = '0019000001EJNfj';
//$_18ID = $_15ID. salesForceIdCalculate($_15ID);

Convert Salesforce 15 Character ID to 18 Character ID Using Javascript

function Convert15CharTo18CharId(id) {
    if (id == null) {
        return id;
    }
    //Scrub quotes from this id
    id = id.replace(/\"/g, '');
    if (id.length != 15) {
        return null;
    }
    var suffix = "";

    for (var i = 0; i < 3; i++) {
        var flags = 0;
        for (var j = 0; j < 5; j++) {
            var c = id.charAt(i * 5 + j);
            if (c >= 'A' && c < = 'Z') {
                flags += 1 << j;
            }
        }
        if (flags <= 25) {
            suffix += "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(flags);
        } else {
            suffix += "012345".charAt(flags - 26);
        }
    }
    return id + suffix;
}

External ID in Salesforce

An External Id is a custom field that has enable the “External ID” attribute. This field is usually references an ID from another (external) system. When a field is marked as external Id, the field will be automatically indexed.

Note: External Id is not case-sensitive – for example, “XYZ” will be matched with “xyz”. if the custom field has enable the “Unique” attribute and the case-sensitive option for that attribute is selected, uppercase and lowercase letters will not be considered identical.

Considerations:

  • External Id is an attribute that can be added to a custom field to indicate that it should be indexed and treated as an Id.
  • It is a user-defined cross-referenced field.
  • It can be created for custom field type (Text, Number or Email ONLY).
  • Each object can have up to 7 external Ids (as of Spring ’15).
  • Configure UPSERT action to traverse object relationships defined in Salesforce, but use External Id’s from legacy system to discover Salesforce record ID’s.

Benefits:

  • It helps improve Report and API SOQL performance.
  • It can be used with UPSERT DML operation to seamlessly integrate apps with other systems.
  • No need to know Salesforce record Id’s to load data.
  • Very convenient for data integrations and migrations.
  • The import wizard will detect existing records in Salesforce that have the same external ID.
  • It becomes searchable in the sidebar search.

Example: If you have an Oracle Financials system that they will be linking with Salesforce, it may be easier for them to be able to refer to the Oracle ID of account records from within Salesforce. So, You can create an external ID in Salesforce and you can load the Oracle ID into that field for each account. You can then refer to that ID field, rather than the Salesforce id.

Difference Between Enterprise WSDL and Partner WSDL

WSDL:
WSDL (Web Services Description Language) is an XML document that describes a web service. WSDL is derived from Microsoft’s Simple Object Access Protocol (SOAP) and IBM’s Network Accessible Service Specification Language (NASSL). WSDL replaces both NASSL and SOAP as the means of expressing business services in the UDDI registry. It is used in combination with SOAP and XML Schema to provide web services over the Internet. A client program connecting to a web service can read the WSDL to determine what functions are available on the server. Any special datatypes used are embedded in the WSDL file in the form of XML Schema. The client can then use SOAP to actually call one of the functions listed in the WSDL.

Salesforce provides a WSDL (Web Service Description Language) files. They are called “Enterprise WSDL” and “Partner WSDL”. The WSDL is used by developers to aid in the creation of Salesforce integration pieces. A typical process involves using the Development Environment (eg, Eclipse for Java, or Visual Studio for .Net) to consume the WSDL, and generate classes which are then referenced in the integration.

Enterprise WSDL:

  • The Enterprise WSDL is strongly typed, which means that it contains objects and fields with specific data types, such as int and string.
  • The Enterprise WSDL document is for customers who want to build an integration with their Salesforce organization only.
  • Customers who use the enterprise WSDL document must download and re-consume it whenever their organization makes a change to its custom objects or fields or whenever they want to use a different version of the API.

Partner WSDL:

  • The Partner WSDL is loosely typed, which means that you work with name-value pairs of field names and values instead of specific data types.
  • This WSDL document is for customers, partners, and ISVs who want to build an integration that can work across multiple Salesforce organizations, regardless of their custom objects or fields.
  • The Partner WSDL is static, and hence does not change if modifications are made to an organization’s Salesforce configuration.

OWD for Standard Objects in New Org

The default organization-wide sharing settings for Standard Objects are:

Object Default Access
Account Public Read/Write
Activity Private
Asset Controlled by
Parent
Calendar Hide Details and Add Events
Campaign Public Full Access
Case Public Read/Write/Transfer
Contact Controlled by Parent
Contract Public Read/Write
Custom Object Public Read/Write
Lead Public Read/Write/Transfer
Opportunity Public Read Only
Price Book Use
Service Contract Private
Users Public Read Only
Private for external
users

Public Full Access:
This option is available for setting the Campaign object only along with other access options. Through public access the user can have the ability to search records, reports, add related records, edit details of the records and can delete the record.
When the Campaign object is set to public full access, all users in that organization can be able to view, edit, transfer and delete.

Public Read/Write/Transfer:
This option is available for Leads and Cases objects only along with other access options. When lead or case objects are set to public read/write/transfer, then all users can view,edit, transfer and report on all the case and lead records.

Public Read/Write:
Whenever a record is set to public read/write the user can view, edit and report on all the records.

Public Read Only:
When a record is set to public read-only the user can search the records, view and report on every record but the user cannot edit that record. Only record owners and assigned users can edit that records.

Private:
When a record is set to private only that record owner and users above that role in an hierarchy can view, edit and report on those records.