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
SudhanwaSudhanwa 

15/18 char salesforce record Id's funda

Hi,

 

 I have this piece of code in my controller that I need to cover in test method - 

 

profileCount = [SELECT count() FROM Profile p WHERE p.name like '%Specific User%' and p.id =: LoginUserProfileId] ;

        if(profileCount > 0)
        {
            isSpecificUser =  true;
        }
        else
        {
           isSpecificUser = false;
        }

 

The condtition never matches as the Salesforce schema fetches 18 chars ID and the browser fetches 15 chars. How can this be achieved?

 

Thanks,

Sudhanwa.

Richie DRichie D

I don't think the 15/18 character id is the problem. It's more likely that the profile name doesn't match '%Specific User%' or for some reason the test method when run doesn't have access to the profile table. (Do you have a runAs statement in your test class?)

 

force.com will match correct 15 or 18 digit ids to the full 18 digit id - try it in eclipse - or for another record type e.g. contact, opportunity etc... in your test method.

 

Good luck.

 

BritishBoyinDCBritishBoyinDC
And if the 15-18 match doesn't work, you can always use a string method to return the first 15 chars - the last 3 are just to make it case insensitive in MS products - Force.com shouldn't need that to make an exact match