Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jbaur-sdocs opened this issue Nov 21, 2023 · 5 comments · Fixed by #98
Closed
Assignees
Labels
bug Something isn't working

Comments

@jbaur-sdocs
Copy link

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 pgajek2 self-assigned this Nov 21, 2023
@pgajek2 pgajek2 added the bug Something isn't working label Nov 21, 2023
@pgajek2
Copy link
Member

pgajek2 commented Nov 21, 2023

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 pgajek2 linked a pull request Nov 21, 2023 that will close this issue
@pgajek2 pgajek2 reopened this Nov 22, 2023
@pgajek2
Copy link
Member

pgajek2 commented Nov 22, 2023

@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
Copy link
Contributor

Thanks for the fast turn around on this!!!

@pgajek2
Copy link
Member

pgajek2 commented Nov 22, 2023

My pleasure @mgellada-sd ! 👯

@jbaur-sdocs
Copy link
Author

Works as expected. Thank you for the quick fix!

@pgajek2 pgajek2 closed this as completed Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants