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
SergiSergi 

Can't save after adding SOQL query

Hi,

I'm writing an apex class, working with Force.com IDE in Eclipse.

When I add the following line to the code, it doesn't upload the code to the server for an unknown error

c = [SELECT Id, Name FROM Account WHERE Id = :c.Id];

 It seems that the problem is in the :c.Id (c is an Account), if I put

Id = 'xxx' //scalar value

in the WHERE section works fine.

Cool_DevloperCool_Devloper

Hi There,

 

Probably the object "c" is NULL until you run the query.

 

So, when you try to access the field Id using "c.Id", it would lead to a null pointer exception.

 

Hope this helps!!

Cool_D

SergiSergi

The object is not null, I've checked it.

I've been working around and seems that the problem ara the single quotes ' ', it's possible?

I need to quote the c.Id field in the SOQL, how can I do that?

prageethprageeth

Your problem can't be due to the single quotes. However if you want a way to put single quotes you can use the following method.

But I don't think that it would solve your problem.

 

String query = 'SELECT Id, Name FROM Account WHERE id = ' + '\'' + c.id + '\'';

sObject conObject = Database.query(query);

c = (Account)conObject; 

return c; 

 

In your code you are querying an Account using the id of the same account(Account c).

 

C = [SELECT Id, Name FROM Account WHERE id = C.Id];

 

Sometimes the problem may be with that.

Try to print the value of C.Id and make sure that C.Id is not null or empty