You need to sign in to do that
Don't have an account?

Trying to retrieve custom fields on the user Profile of the Owner of an opportunity in a formula
I am trying to retrieve custom fields on the user Profile of the Owner of an Opportunity in a formula and can't seem to find a way of getting to it. How can I achieve this?
Thanks
Luc
Follow these steps:
1) create lookup relationship to user from Opp lets say User__c
2) Create a formula field on Opp
TEXT( User__r.Line_of_Business__c )
Here Line_of_Business__c is the custom field on user
3) cerate a trigger on Opp, it is going to be like this
trigger UserLineofBusiness on opportunity (before insert)
{
List<User> us = new List<User>();
Id userId;
for (Opportunity o : Trigger.New)
{
userId = o.OwnerId;
}
us = [select Id,Name from User where id =:userId];
for(Opportunity opp : trigger.New)
{
for (User u :us)
{
opp.User__c = u.Id;
}
}
}
All Answers
Unfortunately the Opportunity.Owner field is a Dead End (that is as far as you can get with a formula). What exactly are you trying to do?
I created a custom fiueld on the User object called 'Line of business'.
In the opportunity I am trying to create a formula field that uses that user's line of business as a criteria to define a certain value.
You can do it for CreatedBy, LastModifiedBy, and $User, but not owner (sorry)
Could I retrieve the opportunity's owner role or profile somehow (that might be a workaround)?
Thanks for the quick replies :smileyhappy:
Really appreciated!
Follow these steps:
1) create lookup relationship to user from Opp lets say User__c
2) Create a formula field on Opp
TEXT( User__r.Line_of_Business__c )
Here Line_of_Business__c is the custom field on user
3) cerate a trigger on Opp, it is going to be like this
trigger UserLineofBusiness on opportunity (before insert)
{
List<User> us = new List<User>();
Id userId;
for (Opportunity o : Trigger.New)
{
userId = o.OwnerId;
}
us = [select Id,Name from User where id =:userId];
for(Opportunity opp : trigger.New)
{
for (User u :us)
{
opp.User__c = u.Id;
}
}
}
Thank you so much for this idea
Have a great weekend
Luc
Hi,
A simpler trigger to do the trick would be :
Of course, this one isn't the most stable one, as the Opportunity owner can be a user or a queue. If your org uses only users as Opportunity owners, then this should be fine.
Thanks. It is the case exactly
How would you adapt it to capture a custom field coming from the user profile and populate the custom field for that field in the oppty (i.e. Line_of_business_c)?
Whoa..
I did not think that the profile object was customizable.. Well .. If it is then you could just extend the formula to pull the field from the profile object.
In your formula field, you could just use the formula as :
User_lookup__r.Profile.Custom_field__c
I'm not sure if I addressed your issue. Let me know otherwise.
Going over the topic once again. I think what you wanted is to have a custom field in Opportunity to show some field from the User object.
You can have a formula field with the formula as:
User_lookup__r.Custom_field_on_User__c