0

This is my first time trying to code a trigger in Salesforce. I have a checkbox labeled "Priority Contact," and I'd like the checkbox to be checked for all contacts that have at least one Opportunity or Meeting event linked to them. Could you please advise on how I should go about doing this? I'm also not 100% sure where to enter the code to activate the trigger. Thank you.

1
  • there's some particular chain from opportunity and contact? i'm talking about lookups and master-details – Christian Croce Nov 11 '19 at 15:35
0

If you're new to writing triggers, I'd recommend checking out SFDC99, which has some great tutorials on Apex for beginners. You'd want to write the code for your trigger in your sandbox, and then deploy it to your production instance once you have perfected the trigger and a test class for it.

To get started, log into your sandbox, go into Setup > Customize > Contacts > Triggers and hit new. That's where you'll enter the code! Then you'll also need to go into Setup > Deploy > Apex Classes > new to add a Test class, and run that to make sure your trigger passes the tests. Check out sfdc99.com and the developer guide.

0
0

If you want to update the field labeled "Priority Contact" on an DML event, then you can write a trigger for that. For this you can simply update the checkbox field of the current contact(trigger.new) and adding a check for eg contact.opportunity!=null. But if you want the checkbox to be checked for ALL contacts that have at least one Opportunity or Meeting event linked to them, then you can simply develop a script for that.

You can learn to write a simple trigger from here http://www.salesforcetutorial.com/apex-trigger-create-simple-trigger/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.