function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hoomelhoomel 

Truncating 18-character Account ID in Query

Hello,

 

i'm currently building a search form where the user can enter search criteria for various fields.

One of those fields is a related Account field.

I am writing the values the user entered into a class variable to use them in a query.

After some troubleshooting I finally read that there are two types of IDs.

Now I am a little bit stuck with truncating the ID i get in a query to compare it with the 15-character ID i get in the lookup field.

 

//the custom object from which i get the fields
public PT_System__c ptsystem;
//the variable where the Account ID from the user field is stored
public String searchAccount;
//this is the query method
public List<PT_System__c> getFilteredAnlagen(){
   		if(ptsystem.name !='' || ptsystem.name != null){
   			searchSystem = '%'+ptsystem.name+'%';
   			}else{searchSystem = '%';}
   		if(ptsystem.account__c != null){
   			searchAccount = ptsystem.account__c+'___';
   		}else{searchAccount = '%';}
  				return [select Id, Name FROM PT_System__c p WHERE p.RecordType.Name='Rental System' AND Name like :searchSystem AND Account__c like :searchAccount order by Name];
   	}

 

 

Currently I am getting an 'invalid operator on field id' error with the query.

Is there any possibility to work my way around this?

The easiest way I think would be to just cut the last 3 characters of the ID field from the query but I have no idea how to accomplish that.

Or is there some other possibility to compare the different IDs?

I would appreciate any help, because that would be one big step to completing my search form.

Best Answer chosen by Admin (Salesforce Developers) 
_Prasu__Prasu_

Easiest way would be converting the 15 char ID to 18 character.

 

if you are getting ID in the String typecast it to Id type and it will get converted to 18 character ID.

 

Id idtest = '5007000000Dcyw4';
system.debug(idtest );

 

you can try out something above.

 

All Answers

_Prasu__Prasu_

Easiest way would be converting the 15 char ID to 18 character.

 

if you are getting ID in the String typecast it to Id type and it will get converted to 18 character ID.

 

Id idtest = '5007000000Dcyw4';
system.debug(idtest );

 

you can try out something above.

 

This was selected as the best answer
hoomelhoomel

Thank you very much, typecasting perfectly did the trick!