beyond-the-cloud-dev / soql-lib

The SOQL Lib provides functional constructs for SOQL queries in Apex.
https://soql.beyondthecloud.dev/
MIT License
63 stars 10 forks source link

.toString() modifies the query, preventing query execution when used with FilterGroup #97

Closed jbaur-sdocs closed 11 months ago

jbaur-sdocs commented 11 months ago

Calling .toString() on a SOQL instance with a FilterGroup leads to a System.StringException when query is executed. We're using .toString() in a logging class to log the query before executing it. It's not clear if doing .toString() before executing is unsupported behavior or if this is a bug.

Steps to reproduce

  1. Run the following query after replacing the Account name and id with an existing Account name and id.
SOQL query = SOQL.of(Account.SObjectType)
            .with(Account.Name)
            .whereAre(SOQL.FilterGroup
                .add(SOQL.Filter.with(Account.Name).equal('Salesforce'))
                .add(SOQL.Filter.id().equal(Id.valueOf('0010500000dsB7bAAE')))
            );
System.debug(query.toString());
Account acc = (Account) query.toObject();
  1. This should throw the following error:
    System.StringException: Bad argument syntax: [at pattern index 9] "{0}}"

Expected behavior

query.toString() should return SELECT Name FROM Account WHERE (Name = :v1 AND Id = :v2) and query.toObject() should return the specified Account.

pgajek2 commented 11 months ago

Hi @jbaur-sdocs!

Thank you for your ticket! Nice work! 🥇

We can treat it as a bug. I will provide fix for it in next 24 hours!

pgajek2 commented 11 months ago

@jbaur-sdocs code is on the main branch. I also added 2 new test methods to cover case you mentioned.

Please check and confirm if it works as expected. 🤝

mgellada-sd commented 11 months ago

Thanks for the fast turn around on this!!!

pgajek2 commented 11 months ago

My pleasure @mgellada-sd ! 👯

jbaur-sdocs commented 11 months ago

Works as expected. Thank you for the quick fix!