You need to sign in to do that
Don't have an account?
Newby code help please
Hi everyone, whilst I have some background in coding in visual basic, I am brand new to apex triggers, but I am having a go. What I'm trying to do is say populate field 'Next Activity Date' on opportunities, based on an open activity linked to the opportunity. The code below is a combination of what I have been able to piece together from websites and this message board so it is obviously a bit rubbish and doesnt work, but hopefully you can see where I'm going. I'd really really appreciate any help anyone can provide me :-)
trigger LastActivity on Opportunity (after insert, after update) {
For (Opportunity opp : Trigger.new)
List<Opportunity> OpsToUpdate = [SELECT (SELECT ActivityDate,
Description,
Subject
FROM OpenActivities)
FROM Opportunity];
System.debug(opp.OpenActivities);
}
Opportunity.Next_Step_Date__c = OpenActivities.ActivityDate
OpsToUpdate.add(opp);
}
2. I think, you should have this trigger on Event instead of opportunity. So if any activity is associated with the Opportunity, it will automatically update the Opportunity's Next Step Date.
3. If you still require trigger on Opportunity, then use before update trigger, put your query outside the for loop to prevent from governor limit.
Many thanks Bhawani - I will make the trigger fire on events/tasks instead as you suggest
How to I get it to referenece the relavant opportunity and the opportunity field please? I am getting a bit stuck here
In Event object, you can use WhatId(Related To) field to find out the parent opportunity object.