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
SFDC-DMGSFDC-DMG 

Help with Apex to update activity field

I am trying to create apex code that will capture either the Lead or Opportunity stage when an associated activity is created or completed.

 

In other words, when someone makes a phone call, I want that activity record to pull in the lead stage at that moment in time so that we can help track leads and activities throughout their lifecycle. Additionally, when an activity is logged on the opportunity, I would like the same thing... essentially, I can then pull activities and what stages they were completed.

 

Any help or other ideas people have around this would be hugely appreciated!

 

Thanks!

logontokartiklogontokartik

You can write a Before Insert, Before Update Trigger on Event & Task, checking for SObject Type either Lead or Opportunity, and get the WhoId or WhatId for Lead/Opportunity and get the Lead Status or Opportunity StageName. Should be fairly simple

SFDC-DMGSFDC-DMG

Great, thank you for the direction on that. I am not very familiar with apex code, so I'm not exactly sure how to write that. If anyone has any direction that can help with the coding, I would really appreciate it.

 

Thank you!