You need to sign in to do that
Don't have an account?
Vishnu7700
If opportunity is closedlost then the realted account activites should be colsed
I had tried with logic as below can any one help to correct the logic.
Code
List<Opportunity> opplist = [Select id from opportunity where StageName =:'Prospecting' and StageName =:'Closed Lost' Limit 2];
List<Task> listtask = [Select id,whatId from Task where Id IN :opplist.Id];
if(trigger.isupdate||trigger.isdelete){
if(Task task : Trigger.old)
if(o.StageName == 'ClosedLost'){
task.Status == 'Completed';
listtask.add(task);
}
update listtask;
}
if(o.StageName == 'ClosedLost' && o.StageName != Trigger.OldMap.get(o.Id).StageName)
instead of
if(o.StageName = 'ClosedLost' && o.StageName != Trigger.OldMap.get(o.Id).StageName)
All Answers
You have to compare opportunity id with "WhatId" field of Task.
Hi error as AND operator can only be applied to Boolean expressions
at line if(opp.StageName == 'ClosedLost' && opp.StageName != Trigger.oldMap.get(opp.Id).StageName){
There was one mistake in variable "setOppId", declaration was "setOppIds" and rest of part i used "setOppId". I have compiled my code and now it is successfully compiled. use below code.
Above is the code and highlited line are part of recent scenario.
I had changed as u said like ClosedLost to Closed Lost
even though getting same error as AND operator can only be applied to Boolean expressions at line 40 column 51
Can you help out how to aviod DML in loop?
I have removed dml operation from loop, see below and use this code.
if(o.StageName == 'ClosedLost' && o.StageName != Trigger.OldMap.get(o.Id).StageName)
instead of
if(o.StageName = 'ClosedLost' && o.StageName != Trigger.OldMap.get(o.Id).StageName)
Yes it working fine now. Assigned Kodos
Thanks Dhaval Panchal
Hey.. Great Solution...