2

Why doesn't this work? I get the error "MALFORMED QUERY"

select AccountId, UserId from AccountTeamMember
where Account.Id = AccountId and Account.OwnerId = UserId

The following works no problem so I know the relationship is correct:

select Account.Id, Account.OwnerId from AccountTeamMember

I basically want to list Account Owners that are also listed as Account Team Members.

1
  • i think it should be select AccountId, UserId from AccountTeamMember where Account.Id =: AccountId and Account.OwnerId =: UserId Note the : after the equals sign. If this does not work i would replace the variables with the hardcoded value just to check if the query is correct and identify what the problem is
    – Prady
    Commented Oct 20, 2014 at 16:10

2 Answers 2

3

SOQL only supports clauses where a field is compared to a literal value. For example, you can't say "where 1", because no field is referenced, nor can you say "where fieldA = fieldB", as no literal is provided. In objects that support custom fields, you can make a formula, such as "fieldA = fieldB", then perform a query in the custom field, such as "where fieldC = TRUE". However, team members can't have custom fields for now, so there's no way to get this in a standard query. External reporting tools, such as Crystal Reports, as well as traditional databases, such as MySQL, can query this data. Typically, this means exporting the contents of both tables into CSV files, importing them into the external system, then querying. Crystal Reports handles all the steps at once, for example, but it's not a cheap application.

Alternatively, you can query this data into a browser and process the results client side, or in Visualforce controller code server side.

1
  • Thanks you're correct. I tried changing the query to this and it stopped complaining: where Account.Id = '111111111111111' and Account.OwnerId = '111111111111111'
    – JJCoolJ
    Commented Oct 20, 2014 at 17:11
0

I don't have account teams enabled in my org, but if you try

select AccountId, UserId from AccountTeamMember

in the developer console's Query Editor, and then follow it with

select AccountId, UserId from AccountTeamMember
where Account.Id = AccountId 

and then, if necessary

select AccountId, UserId from AccountTeamMember
where Account.Id = AccountId and Account.OwnerId = UserId

You'll see the part of the SOQL statement that is causing the error.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .