1

I am trying to query a list of the names of a custom object. I am querying the "Name" field, but every time I try to assign this query to a new variable (List), I get the error: Illegal Assignment from ID to List(string) or List(CustomObject__c) (pending on what type of list I am trying to make it). IS there any reason that the following code is querying as an ID?

public List<CustomObject__c> SNANAList = [SELECT Name FROM CustomObject__c WHERE Account__c = :userinfo.getUserID()].Account__c;

As you can see, the query goes to get the name of each record that is associated to the user's account. The custom Object has a lookup to the Account object. Any help would go a long way.

Many Thanks, CP

1

Removing the .Account__c at the end of your query will allow you to assign the queried value to a list.

public List<CustomObject__c> SNANAList = [SELECT Name FROM CustomObject__c WHERE Account__c = :userinfo.getUserID()];

However, using the filter Account__c = :userinfo.getUserID() will return no results, as no user will have an id value which is the same as an Account Id. You will want to adjust this to return the values you need.

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.