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

Trigger lookup(relationship) from:parent to:children
Hey.
I would like to get a lookup(relationship) field from an Account to all related Opportunities. I know I can access the Account field via formula field from the Opportunity, but then only get it as text value, where I would like to have it as lookup(relationship) type on the Opportunity as well.
Example: Have the Account Owner on all Opportunities. (not really a necessaty, only an example to understand what I would like)
Is there a how to what steps to follow on how to achieve this?
Thanks for the help in advance.
I would like to get a lookup(relationship) field from an Account to all related Opportunities. I know I can access the Account field via formula field from the Opportunity, but then only get it as text value, where I would like to have it as lookup(relationship) type on the Opportunity as well.
Example: Have the Account Owner on all Opportunities. (not really a necessaty, only an example to understand what I would like)
Is there a how to what steps to follow on how to achieve this?
Thanks for the help in advance.
http://thysmichels.com/2013/01/31/visualforce-lookup-field/
See how I used Account.OwnerId & Account.Name in the SOQL.
You can add the account owner through a formula field - simply followw the relationship:
Account.OwnerId
There is the same lookup(custom object) field on Accounts and Opportunities. Do I not need a trigger to get the value when set in Accounts to all Opportunities?
Checkbox
Currency
Date
Date/Time
Number
Percent
Text
But not as a lookup(relationship) on the Opp, right?
Now I would like the same lookup(relationship) field that references the custom object on the Opportunity, with the value equal to the value in the lookup(relationship) on the Account.
Assuming that the lookup field is named 'Custom_Object__c' (which means the relationship is named Custom_Object__r), you just follow the relationship to the account, then follow the relationship from the account to the custom object. This works for up to 5 levels.
The field 'Sales Agent' is a lookup on the custom object 'Acquirer' on the Account. I know that I can query all information from the Opportunity and display it as text value. What I would like though is to have a field on the Opportunity which has the same functionality as the Sales Agent on the Account. with a link to the custom object. And whenever I change the Sales Agent on the Account, the Sales Agent also changes on all Opportunities.
I am pretty confident, that this wouldn't work with a formula field, would it?
You can use follwoing formula field:
Formaula Type = text
Formula value = Account.Sales_Agent__r.Name
If you want a link like lookupfield then you have to write a trigger on Account and opportunity and when ever opportuntiy is inserted or account is update with changed sales agent then you can update sales Agent lookup field on opportunity.
F.e. do I need an apex class?
You'll need to create a field that is a lookup to the Sales_Agent__c record and then I reckon you'll need a couple of triggers:
1. A before insert trigger on opportunity, that copies the field from the account to the opportunity. This will need to be 'bulkified' and handle the situation where up to 200 records have been inserted, each of which could potentially have a different account parent.
2. An after update trigger on account, that updates all of the child opportunities when the field on the account changes. This will also have to be bulkified, and handle the situation where the field is changed on up to 200 records at once.