2

We have discovered SOQL Profile Id Bug Introduced in Summer 2019 Release.

To reproduce this, we need to have either a Custom Object or Custom metadata with Custom Field of Text field which contains Profile Id and make a query on that Custom Object or Custom Metadata. Previously, regardless if case-sensitive or case-insensitive Profile Id was stored in that field, SOQL statement was able to return and match those records.

In Summer 19 release, SOQL statement doesn't return records if value of profile Id stored in field has 15 symbols.

In our case we use Custom Metadata but this can be easily reproduced by Custom Object.

Listing of Field definition

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <deploymentStatus>Deployed</deploymentStatus>
    <fields>
        <fullName>Profile_Id__c</fullName>
        <externalId>false</externalId>
        <label>Profile Id</label>
        <length>255</length>
        <required>false</required>
        <trackTrending>false</trackTrending>
        <type>Text</type>
        <unique>false</unique>
    </fields>
    <label>Custom Object</label>
    <nameField>
        <label>Custom Object Name</label>
        <type>Text</type>
    </nameField>
    <pluralLabel>Custom Objects</pluralLabel>
    <sharingModel>ReadWrite</sharingModel>
    <visibility>Public</visibility>
</CustomObject>

Listing of simple class which reproduces that problem

public class Summer19Bug {
    public static void detect() {
        Custom_Object__c co = new Custom_Object__c(Profile_Id__c = UserInfo.getProfileId().left(15));
        insert co;
        System.debug(LoggingLevel.ERROR, '@@@ v: ' + co.Id );

        List<Custom_Object__c> cos = [ SELECT Name FROM Custom_Object__c WHERE Profile_Id__c = :UserInfo.getProfileId() ];
        System.debug(LoggingLevel.ERROR, '@@@ cos: ' + cos );
        System.assert(cos.size() > 0, 'Fails in Summer 19 and works good in Spring 19 and earlier versions.');
    }
}

I can provide our workaround in my answer, but I wonder why this behavior has changed, was the previous behavior considered as a bug or the current behavior is a bug, why this behavior was changed but not documented in Release Notes.

If anyone knows better workaround that my own or anyone knows why this behavior has been changed, please add your answer.

0

In our workaround (since we have records on both production and sandboxes which have case-sensitive Profile Ids of 15 symbols stored in Custom Metadata records), we changed the SOQL query part to look for 15 symbols Id

public static void workaround() {
        Custom_Object__c co = new Custom_Object__c(Profile_Id__c = UserInfo.getProfileId().left(15));
        insert co;
        System.debug(LoggingLevel.ERROR, '@@@ v: ' + co.Id );

        List<Custom_Object__c> cos = [ SELECT Name FROM Custom_Object__c WHERE Profile_Id__c = :UserInfo.getProfileId().left(15)  OR Profile_Id__c = :UserInfo.getProfileId() ];
        System.debug(LoggingLevel.ERROR, '@@@ cos: ' + cos );
        System.assert(cos.size() > 0);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.