+ Start a Discussion
Dan DuncanDan Duncan 

How to convert or truncate 18 character ID back to 15 characters

I am using a VisualForce page that searches for an object within a different web-based system and displays it on the record page in SF.  In my case, it is pulling the object ID in SF and passing that to the other site and searching for a record that matches this ID.  The problem I have is that in my other system I am using the 15 digit IDs but the VF page is using the 18 digit ID so it is not finding what I am looking for.  Here is my markup I am using:

<apex:page standardController="Account" title="Workspace corresponding to an account">
  <apex:iframe scrolling="true" title="Account Workspace" src="<WEBSITE URL?sfSession={!$Api.Session_ID}&sfUrl={!$Api.Partner_Server_URL_70}&smallDisplay=Y&ws={!URLENCODE(account.id)}"/>
</apex:page>

When I look in the URL of the object page I see this ID:

001G000001WraVp

But my VF page is passing this ID:

001G000001WraVpIAJ

I know about the CASESAFEID formula operator that will convert the 15 digit ID to the 18 digit but I am sort of looking for the opposite.  Or if there is a way that I could truncate the ID down to 15 or something that also might work.  I realize that it would be better to use the 18 digit IDs in my other system but I already have a lot of data there and it would be a ton of work to go and change it at this point.  Any Ideas?  I am not real savvy on this stuff yet so go easy on me :)


Best Answer chosen by Dan Duncan
KaranrajKaranraj
You can use LEFT function to truncate value in visualforce page. Try the below code

<apex:page standardController="Account" title="Workspace corresponding to an account">
  <apex:iframe scrolling="true" title="Account Workspace" src="<WEBSITE URL?sfSession={!$Api.Session_ID}&sfUrl={!$Api.Partner_Server_URL_70}&smallDisplay=Y&ws={!URLENCODE(LEFT(account.id,15))}"/>
</apex:page>

All Answers

KaranrajKaranraj
You can use LEFT function to truncate value in visualforce page. Try the below code

<apex:page standardController="Account" title="Workspace corresponding to an account">
  <apex:iframe scrolling="true" title="Account Workspace" src="<WEBSITE URL?sfSession={!$Api.Session_ID}&sfUrl={!$Api.Partner_Server_URL_70}&smallDisplay=Y&ws={!URLENCODE(LEFT(account.id,15))}"/>
</apex:page>
This was selected as the best answer
Dan DuncanDan Duncan
Karanraj,
Thank you for the quick response!!  That looks like it should do exactly what I want, I will do some testing and report back.  
Dan DuncanDan Duncan
That looks to be working great Karanraj, thanks again!
Tristam Tredgett 3Tristam Tredgett 3
My org works with an ERP system that has 15 digit salesforce id's.  As we add new accounts from the ERP Salesforce is creating 18 digit ID's.  Is it ok to have 15 and 18 digit id's in the ERP or shall we just stick to 15.  If I have to convert them should I us the code mentioned above?
Rahul H 4Rahul H 4
Hi Everyone, Can you please help me in writing a trigger to truncate the characters on a field

We are loading the Case from the website. There is an issue with Images field in Case entity as displayed below:

Text in Images Field in Case entity : ["https:\/\/www.intops.com.au\/wp-content\/uploads\/gravity_forms\/2-cb870933d1056667864f32a0efe9bcff\/2018\/08\/MDC3521112.JPG";]
 
So, everytime we have to remove the junk characters and set it as below and check the images.
 
Need update: https:\\www.intops.com.au/wp-content/uploads/gravity_forms/2-cb870933d1056667864f32a0efe9bcff/2018/08/MDC3521112.JPG

Can you please help to write a trigger to truncate the junk characters. Thanks a lot