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
sfdev1sfdev1 

Contact lookup field on Opportunity (Custom)

I want to add a contact lookup field to Opportunity object so that I know which contacts related to an Account relate to that Opportunity. This means that when I select the lookup button I want the system to onkly lookup contacts related to that Account.
 
Would I somehow have to limit the lookup list with the use of Apex code?
 
Thanks
 
Stephen
werewolfwerewolf
There is not yet a way to limit the scope of lookups, although that is a highly requested feature on IdeaExchange.  There already is an area of opportunity called Contact Roles which you can use for this purpose, btw.
sfdev1sfdev1
How would the Roles be used to limit the contact list then?
werewolfwerewolf
Sorry, I was not suggesting that Contact Roles can be used to limit the list.  I meant that Contact Roles are a pre-existing means of associating Contacts to Opportunities.
JESUtimacoUSJESUtimacoUS
The next question for me is, how to use contact roles when trying to relate an opportunity to a custom object, and want to transfer selected contacts to the custom object. 

I have a custom object (Projects) that is created through an opportunity, I am able to transfer Account info, Rep ID (translated into Rep name through a table formula) etc., but not Contacts identified in the Contact Roles. 
fb123fb123
I am trying to accomplish the same and haven't had much luck. I have a child object of Opportunity that needs to reference fields (in formulas and some e-mail templates originating from its records) from the Opportunity's Contact Roles.

Has anyone had any success with this? Why can't a Contact Role be referenced from other standard and custom objects? I've considered creating another junction table for Opportunities and Contacts, but that seems fairly redundant considering that the OpportunityContactRole junction table already exisits.

Thanks in advance.
werewolfwerewolf
Well, for one, you can never access one-to-many objects via formulas – since there can be many Opportunity Contact Roles, how would the formula know which one to address?  You'd have a similar problem if you created your own junction object.

You can access the rows of Opportunity Contact Role with Apex though.