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
beachhawkbeachhawk 

Lookup formula value in custom object

We have a table of scoring values.  So I created a custom object RFM__c.  So the there are 4 main columns.  Value(name), Recency, Monetary, and frequency. 

 

There is formula for each, for example Recency =( today-Max(createddate,lastmodify,lastactivity))/30.  So say the result of the formula was 1.  I want look up the value in the RFM__c object and return the recency value.

 

I tried to create a formula field with the equation and link it to the RFM__c but had no luck.  

 

I am new to the salesforce environment and could use someone to point me in the right direction. 

 

 

yudhvirmoryudhvirmor

Did you setup relationship between your custom Object and another object whre you want to do lookup. First create relation between two objects and then use formula lookup.

JayantJayant

OK, suppose you have two objects, RFM__c which has the field that you want to lookup and set on another object Obj__c.

For this go to Setup - >Create->Objects->Obj__c and create a new custom field on this of type LookUp Relationship.

Specify the object that has the field you want to lookup, complete the wizard and you are done.

 

In this case Obj__c is the child and RFM__c is the parent.

 

If you want the field to be mandatory, set it from layouts or else go for Master Detail Relationship but in this case when you delete a record on RFM__c, all related records on Obj__c would also be deleted, though it's not the case with Lookup Relationship.

beachhawkbeachhawk

thank you for the help.

 

I have tried to do this, All the Field in the parent are available but the the formula field that I have in the child does not show up as a availible field.  Can I not have a formula field  as what I use for a lookup?

JayantJayant

Suppose you have 1000 records on Parent object then how you can decide to which record in the parent your child should get related. Logically, first their should be a parent and then only a child can exist.

 

What is your exact scenario, can you detail that, then we shall be able to sort this out.

 

No, you should use a Lookup Relationship/Master-Detail Relationship type field for a Look Up, that's why they exist.

If need be, you may also specify filtering criteria so that the values that you can select in a Lookup are restricted to select few.

 

Thanks.

JayantJayant

A formula field can normally have only the fields on the same object.

 

If your formula is a Cross Object one, then you should have some LookUp or Master-Detail relationships.

 

You can access the fields of either the same object on which the field resides or of a parent object.

 

So anyways to use the field of parent (in your case, RFM__c), you will still need a lookup to RFM__c in your child object.

After you have a Lookup to RFM__c in your object Obj, you may use any of RFM__c fields in formula fields of Obj object.

 

If you don't have a Parent-Child relationship i.e. your objects are unrelated and still you want to calculate a field on an object based on some field in another unrelated object or even based on child's field in case the field is on parent, you should write an Apex Trigger to achieve this.

 

Thanks a lot.