You need to sign in to do that
Don't have an account?
Trigger Assistance Requested
Good day to those reading this. I am an administrator by design with very little code experience. Recently, we lost our developer and I am now responsible for taking this challenge on......okay, I will pause here and allow those playing the violin to finish. :)
I am wanting to create a trigger, based off the information below:
When an Opportunity is created, it creates/converts to Stage=Intake.
At this point, we wait for one of our Associates to schedule an Appointment for this Opportunity. Appointment is a custom object (Appointment__c).
The trigger I am needing assistance with is:
Opportunity stage=Intake and Opportunity field Initial_Appointment_Date__c is NULL.
When a first appointment record is created and seen associated to the opportunity where the criteria above is true, then populate Initial_Appointment_Date__c with the date that first Appointment record was added and change the Opportunity stage to Scheduled.
Can anyone be so kind as to help me with this trigger? Thank you in advance....
Robert
Is Appointment linked to the opportunity by Master-Detail or lookup relationship?
Then you can create a trigger on Appointment__c that queries the linked opportunity, and if the criteria are met, updates the opportunity. Could be an after create trigger
Just a lookup relationship. I originally thought, because of my lack of code knowledge, that I could simply export out all my appointment data, then delete. Create the Master-Child, re-import my data, and create a SUM roll-up summary field and then build a workflow that bases the above off the greater than 0 criteria to achieve the same result. But, I wanted to come here and see if it would be easier to get help with a trigger versus do all that work. :)
rtuck2009,
You don't need a trigger for this action. Presuming that Appointments objects are related to Opportunity objects in a 'Master-Detail' relationship, you can use a workflow rule to update the Initial_Appointment_Date__c and set the Stage value on the Opportunity related to an Appointment. The steps for this are below.
1. Create the workflow rule on the 'Appointment__c' object.
2. In the workflow rule, use the 'Formula' option to chose when it evaluates, and set your formula to the following:
AND(Appointment__c.Opportunity.StageName = "Intake", ISBLANK(Appointment__c.Opportunity.Initial_Appointment_Date__c))
3. n the workflow actions, create two new field updates.
The first is to set the Opportunity Stage to 'Scheduled'. The second is to set the 'Initial_Appointment_Date__c' to a value of 'TODAY()'.
However, if you are using a 'Lookup' relationship between the two records, then you will need a trigger. The one below should meet your needs. You will need to create a test method for this trigger before you can install it in your environment. I leave that as an exercise for you.