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
Andrew PleshachkovAndrew Pleshachkov 

Get Contact Role in SOQL query

Salute.

I'm trying to add to the contact list page an indication of the role of each indirect contact. Like this:

   public List<Contact> Contacts { get{  
     return [SELECT Id, Name, Account.Name, Title, Email, Phone, Relations__c FROM Contact LIMIT 1000];  
   } set;}  
   
   public List<Role> Roles { get{  
     return [SELECT Role FROM AccountContactRoles];  
   } set;}  I tried adding Role or AccountContactRole fields, but they are not recognized. What I need to do?
I tried to indicate the Role field in the first request, but received a recognition error (which is logical, there is no such field in the standard contact card).

Then I made the second request only for roles, but it also produces Compile Error: Invalid type: Roles.

What i need to do?
EldonEldon
Hi Andrew,

Try the following SOQL query:
 
[SELECT Role, Contactid FROM AccountContactRole]

Regards
Patrick LEBRETTEPatrick LEBRETTE
Hello Andrew,

can you try this 
SELECT Id, Name, Account.Name, Title, Email, Phone, Relations__c, (select role from AccountContactRoles) FROM Contact LIMIT 1000 ?

Regards
Andrew PleshachkovAndrew Pleshachkov
Thank you guys! both options were compiled by Apex; but how to know the full name of the 'Role' resulting field for the VF page?

<apex: column value = "{! contact.Role}"/> fails in all interpretations.
Patrick LEBRETTEPatrick LEBRETTE
Hello Andrew,

did you try something like {!contact.AccountContactRoles.Role} ?

Regards
Andrew PleshachkovAndrew Pleshachkov
Thanks for the answer!
For an unclear reason, a direct reference to a Role via ACR did not help either.
In the end, I decided simply through the custom field for the contact, to which I connected the value ACR.Roles in the controller.