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
Timothy KeithTimothy Keith 

Apex Trigger to populate custom field on Opportunity Object.

I need to write an apex trigger that takes information from some of Opportunity fields and uses them to generate a value for a custom field.
For example, say I have a custom field called "All Opportunity Members." When I create a new opportunity or any time it is edited, the trigger should fire and (using apex code i would write) and populate the Area Code field with the Opportunity Contact Role Members and the Opportunity team members.

The problem is that the triggers I write don't seem to fire correctly. I just start to learn how to write a little code but I am struggling. How can I make a trigger that fires correctly when a record is created or edited?
 
praveen sonepraveen sone
Tim,

Why do u want to write a trigger here? You can use a "Workflow Rule" with the below procedure.
1. workflow rule on "opportunity" object.
2. Evaluation criteria "When the record is created,edited"
3. Set the rule criteria to "formula evaluates to true" --> Enter "TRUE". --> Save & Next
4. Then set the "Workflow actions" --> Field update -->
5. Choose the field to update as "Area Code". --> then choose "formula" to set the value
6. Enter your formula in the formula editor to populate this field.
7. Save
8. Do not forget to Activate the workflow.

If this helps. Mark this as solved. Thanks!
Timothy KeithTimothy Keith
Hey Praveen,

Thanks for the quick response. 

How do I make a forumla in formula editor that that would show the contact roles and opportunity team members? 

I am not sure how to do this. 

Thanks! 
REVNAREVNA
Basically you want to update the field on parent , with the information from its children records ?
Timothy KeithTimothy Keith

No, I want to update a text area feild with the opportunites's contact roles and team members. The text area feild will be on the opportunity itself not an parent. 

Best,
Tim