One of the custom objects I have is rendered as a Related List of Opportunity. This custom object also has a custom field of Opportunity lookup type. To create a record of this type I go to Opportunity -> Related List
and click on New
button.
What I want is : At the time of record creation I want to assign default values to certain fields. The way it should work is Mailing Address
field should get its value from related Opportunity's primary Contact. I can achieve this in a trigger by executing a query like
SELECT MailingAddress
from CONTACT
WHERE id IN (SELECT contactID
FROM OpportunityContactRole
WHERE opportunityID = <variable> and isPrimary = true)
However, I want to do it by assigning a formula to the default value to Mailing Address filed directly. Is it possible?
Second part of this question is... While trying to set the default value for this custom field I tried something like Opportunity__c.Mailing_Address__c
(This is a custom field on Opportunity), however the formula validation error I got was
Error: Field Opportunity__c does not exist. Check Spelling
. Opportunity__c
in fact exists as a lookup Opportunity Field in my custom object.
Any pointers are greatly appreciated.
Thanks