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
cdweaver333cdweaver333 

Not sure if I need a workflow rule or trigger - Can you help?

We want to build reports using email addresses of contracted opportunities.  We can do this through the "Contact Roles" in Opportunities.  However, it is not required so very few of our users follow my instructions to fill it out.
 
1) Is it possible to design a workflow rule where if an opportunity is created and saved, the user must fill in something in the Contact Roles section?
 
2) If not - We have a lookup field in opportunities called Primary Contact (looks in Contacts tab for appropriate person).  Below that, I created a field called "Primary Contact Email".  Is it possible to design a trigger where if a name is inserted into the Primary Contact field via the lookup, the email address of that contact will automatically be pulled into the field "Primary Contact Email"
 
Thank you for any help you can provide!
 
 
MikeGoelzerMikeGoelzer
A thought -- try going to Setup | Security | Field Accessibility and see whether simply making some of the optional (by default) fields on Opp. into mandatory ones would solve the problem with users not filling in the forms.

To answer your questons, though --

1.  Yes, but look at "validation rules."  It's an easy way to prevent a record from being saved unless certain conditions are met (like all the fields are filled in).

2.  Yes, definitely.

(Workflow and triggers are the same idea -- automated tasks that run after you press "save" on a new or updated record -- with the difference being that the former is both simple and rather limited, and the latter is complicated but very flexible.)
cdweaver333cdweaver333

Mike,

Thank you for your thoughts.  I went to Security Controls but Contact Roles is not on the list since it is a related list and not a field in Opps.

I have found that you can't do a validation rule for a related list.  So I'm left with workflow and triggers. 

I've experimented with both.  I will try to track down some workflow code that is able to replicate what I need to do...

jrotensteinjrotenstein
You can do it via a trigger. Have a look at this entry on my blog which has a Trigger for OpportunityContactRole on Close.

The code is:
Code:
trigger SetPrimaryContact on Opportunity (before update) {

   for (Opportunity o : Trigger.new) {
     // Check if the Opportunity just closed
     if (o.IsClosed && !Trigger.oldMap.get(o.id).IsClosed) {
       OpportunityContactRole contactRole =
            [select ContactID from OpportunityContactRole where IsPrimary = true and OpportunityId = :o.id];
       if (contactRole != null) {
         o.Primary_Contact__c = contactRole.ContactID;
       }
     }
   }
 }

 Glad to know it helped you!


Message Edited by jrotenstein on 10-17-2008 06:13 AM
cdweaver333cdweaver333

John,

Awesome info!  That was exactly what I was looking for...Thank you for your help....

Devon