You need to sign in to do that
Don't have an account?
Rahul
I need to update the old opportunity records with stage as closelost if those record is with with stage prospecting since more than 90 days. i
The Idea is when i create a new opportunity and change the stage to Prospecting it should run this trigger and check if any old opportunities with stage Prospecting and which was created 90 days ago and convert that to closelost.
trigger UpdateRiskStatus1 on opportunity (after insert,after update) {
List<opportunity> fvr = new List<opportunity>();
for (opportunity objvr :[select Id , stagename from opportunity where stagename='pending' and createddate < LAST_90_DAYS])
{
for(Opportunity op :trigger.new){
if(op.stagename == 'prospecting')
{
objvr.stagename='closed lost';
fvr.add(objvr);
}
}
}
upsert fvr;
}
trigger UpdateRiskStatus1 on opportunity (after insert,after update) {
List<opportunity> fvr = new List<opportunity>();
for (opportunity objvr :[select Id , stagename from opportunity where stagename='pending' and createddate < LAST_90_DAYS])
{
for(Opportunity op :trigger.new){
if(op.stagename == 'prospecting')
{
objvr.stagename='closed lost';
fvr.add(objvr);
}
}
}
upsert fvr;
}
All Answers
First, I want to mention that the previous two answers have bugs in their code, and I do not recommend using their provided code.
Second, while you can do what you are asking with a trigger, your logic is slightly flawed and you should not be waiting for an update event to trigger your logic for other unrelated records.
Instead, you should be performing this with a time delayed workflow which will trigger upon Stage = 'Prospecting', and execute an action 90 days after the trigger date to set the Stage to 'Closed Lost'. This will give you the expected behavior you are looking for and I recommend it over the trigger you are trying to create.
Please mark this answer as correct if it helped you!
David @ Configero your Answer is for future records but I needed it for old records also. The solution provided by Raj V is working Perfectly for Me. Thanks Once again Every one.