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
rosscorossco 

Default a value to a related record's value

How does one default (or formularise) the value of a field to the value of another field in a related record?

 

I have a new object A that is a child of Opportunites but is also related to an account and am trying to set the value of A.Account to that of Opportunity.Account

 

Thanks in advance

Ross

 

jhurstjhurst

Ross,

 

There are a few ways to do this.

 

1. You can create a button that you would use to create the custom objetc (in this case you would add the button on the opportunity).  The button would essentially use variables in the URL to set the field.  You would need to look at the elements of the custom object edit page to get the field ID of teh Account field.  Once you have that, you would create the button to go to:

 

     /a00/e?CF00N40000001SHRK={!Opportunity.Name}&CF00N40000001SHRK_lkid={!Opportunity.Id}&CF00N40000001SHRJ={!Opportunity.Account}&CF00N40000001SHRJ={!Opportunity.AccountId}

 

Here a00 is the key prefix of the custom object (first 3 characters of the id), CF00N40000001SHRK is the id of teh Opportunity field, CF00N40000001SHRJ is the ID of the Account field.

 

The drawback to this method is that if someone creates a custom record though a different method (like the API) the defaulting will not be enforced.  It will only work for teh new button.

 

2. You can override the standard Edit function for the custom object with a Visualforce Page.  This will allow you to default any field you want.  The drawback here is that you have to recode the edit page and it still does not cover the instance of perople creating the records through the API.

 

3. You can create an Apex Trigger to automatically set the values when the record is created.  This will also require coding, but will guarantee that every record created will have the values you want.

 

I would suggest a combination of 2 and 3 in order to make sure that the values are set in the ways you want.

 

Hope this help.

Jay