{"id":1717,"date":"2009-10-02T13:36:22","date_gmt":"2009-10-02T08:36:22","guid":{"rendered":"http:\/\/www.chiragmehta.info\/chirag\/?p=1717"},"modified":"2009-10-02T13:36:22","modified_gmt":"2009-10-02T08:36:22","slug":"algorithm-for-converting-15-digit-salesforce-id-to-18-digit","status":"publish","type":"post","link":"https:\/\/www.chiragmehta.info\/chirag\/2009\/10\/02\/algorithm-for-converting-15-digit-salesforce-id-to-18-digit\/","title":{"rendered":"Algorithm for converting 15 digit Salesforce Id to 18 digit"},"content":{"rendered":"<p>Following is an algorithm I found on Salesforce Community. It converts a 15 digit salesforce Id to the corresponding 18 digit Salesforce Id. This is pretty helpful in onclick JavaScript codes and S-Controls where merge fields normally return only 15 digits. Also, although the code is in JavaScript, it can be easily converted to any other coding language code.<\/p>\n<p><code>function normaliseSforceID( id) { \/\/ fluff up a 15 char id to return an 18 char id<br \/>\nif (id == null) return id;<br \/>\nid = id.replace(\/\\\"\/g, ''); \/\/ scrub quotes from this id<br \/>\nif (id.length != 15) {<br \/>\n \/\/print('well, id is not 15, bye' + id + ' ' + id.length);<br \/>\n return null;<br \/>\n}<br \/>\nvar suffix = \"\";<br \/>\nfor (var i = 0; i < 3; i++) {\n var flags = 0;\n for (var j = 0; j < 5; j++) {\n  var c = id.charAt(i * 5 + j);\n  if (c >= 'A' && c < = 'Z') {\n   flags += 1 << j;\n  }\n }\n if (flags <= 25) {\n  suffix += \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".charAt(flags);\n } else {\n  suffix += \"012345\".charAt(flags-26);\n }\n}\nreturn id + suffix;\n}<\/code><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following is an algorithm I found on Salesforce Community. It converts a 15 digit salesforce Id to the corresponding 18 digit Salesforce Id. This is pretty helpful in onclick JavaScript codes and S-Controls where merge fields normally return only 15 digits. Also, although the code is in JavaScript, it can be easily converted to any [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[169],"class_list":["post-1717","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-salesforce","post-preview"],"_links":{"self":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/comments?post=1717"}],"version-history":[{"count":2,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1717\/revisions"}],"predecessor-version":[{"id":1719,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1717\/revisions\/1719"}],"wp:attachment":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/media?parent=1717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/categories?post=1717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/tags?post=1717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}