0

I'm encountering some very strange behavior in my org's full sandbox. This does not seem to be happening in our production org.

I have a query in code that looks like;

[Select Name, Id From ContentWorkspace where Name='My Name' limit 1]

This is causing my application to fail out. When I check the logs, the query looks like this;

SELECT Name, Id FROM ContentWorkspace WHERE Name = 'My Name' LIMIT 1

Notice how the capitalization of the key words is different. This query returns 0 results, and that's where my code fails.



Here's where things get weird. When I run this query, I get 1 result as expected;

SELECT Name, Id FROM ContentWorkspace WHERE Name = 'My Name' limit 1

And the final weird part. The following query returns a result;

SELECT Name, Id FROM ContentWorkspace WHERE Name = 'My Name' LIMIT 2


So I'm wondering what's going on here. It appears that salesforce automatically changes the case of my code query to be all uppercase, but that causes problems. Any advice on how to approach this would be very helpful!

Edit: Here is some further context;

ContentWorkspace LibraryRec = [Select Name, Id From ContentWorkspace where Name='My Name' limit 1];
    String sLibID = ''+LibraryRec.ID;

Produced the following error;

10:09:33:210 FATAL_ERROR System.QueryException: List has no rows for assignment to SObject
0

I faced kind of similar issue not related to the change of case but yes exception when we put limit 1. So Whenever we use limit one and variable to which you are assigning this result is not a list, it is just a single object ContentWorkspace LibraryRec then it will throw error if there is no result found. Because it expects a result from that query. so just make the result type as List<ContentWorkspace> .

List<ContentWorkspace> LibraryRec = [Select Name, Id From ContentWorkspace where Name='My Name' limit 1];
if(LibraryRec != null && LibraryRec.size() == 1)
    String sLibID = ''+LibraryRec[0].ID;

If there is no record then it the list will have Zero size.

| improve this answer | |

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.