2

I am using opportunities in Salesforce to track professional services engagements.

As soon as the opportunity is won and closed, I will fill in a custom field called "number of days" which represents the number of man-days sold for the given opportunity e.g. 100.

I now use events inside the opportunity to track the engagement with the customer. I can have several events that may last from 1 day and up.

Can I sum the # of days in all the events and can I subtract that number from the custom field in the opportunity?

I am using the standard event object that is part of the opportunity by default (when creating an activity).

Thanks

5
  • Are you using standard Event object or custom Event__C object? if its custom object what is relation between OPP and event ? (lookup or master-detail ) Commented Feb 12, 2016 at 4:26
  • It is the standard event that you can create as an open or past activity Commented Feb 12, 2016 at 5:09
  • Will you consider to use Apex?
    – Ashwani
    Commented Feb 12, 2016 at 5:31
  • Yes. I will have to learn how :-) Commented Feb 12, 2016 at 5:34
  • I can tell you the approach, you will have to code yourself. Will it work?
    – Ashwani
    Commented Feb 12, 2016 at 5:34

1 Answer 1

1

I can tell you the approach achieving using Apex.

  1. Get all Event records related to opportunity (Activity)
  2. Using start and due date of each event record find number of days between start and end date. Use Date class method daysBetween(secondDate). It will return number of days.
  3. Using above method get all days number and sum all.
  4. You already have total # of days in custom field. Subtract is from the sum you calculated in previous step. Store wherever you want.

Another approach to skip above point #2

  1. Create formula field in Event like End_Date - Start_Date. This will calculate # day for the record.
  2. Using above field get all days number and sum all using trigger.
  3. Within trigger subtract it with total # of days and store it. (Process builder may not work). Trigger would on Event object running on After update. Use Related to ID field to get Opportunity value.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .