Solved

Salesforce - reference field lookup syntax

Posted on 2011-09-19
1
1,507 Views
Last Modified: 2016-02-16
Newbie Question -
 I am trying to write a trigger which creates a new task when the Contract is saved.
In the task I need to populate the Sales_Name__c field with the value from the contract field Sales_Rep_c.
I am getting a compile error indicating an invalid foreign key relationship for c.Sales_Rep_c.
Here is the line generating the error;

Sales_Name__c = [SELECT Name From User Where Id = : c.Sales_Rep_c.id];


If I look at the properties of the Contract field Sales_rep_c it is a reference(custom) with foreign key Sales_rep_r
The Contract field Sales_Rep_c is populated with the correct id value for the user name.
0
Comment
Question by:Ed_CLP
1 Comment
 
LVL 11

Accepted Solution

by:
techhealth earned 500 total points
ID: 36571032
It should be like this:
Sales_Name__c = [SELECT Name From User Where Id = : c.Sales_Rep__r.id];
or
Sales_Name__c = [SELECT Name From User Where Id = : c.Sales_Rep_c];

The former is a way of retrieving through the relationship; the second is simply using the reference field, which stores the Id itself.  The second is prob. more efficient.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: You must have administrative privileges in order to create/edit Roles. Salesforce.com (http://www.salesforce.com/) (SFDC) is a cloud-based customer relationship management (CRM) system. It is a database most commonly used by sales and marke…
Salesforce.com is a cloud-based customer relationship management (CRM) system. In this article, you will learn how to add and map custom lead and contact fields to your Salesforce instance.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question