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
Deepak agarwal 9Deepak agarwal 9 

Error on task list

trigger deleteoppafter on Opportunity (after delete) {
if(trigger.isafter && trigger.isdelete){
    list<task> t=new list<task>();
    t=[select whatid from task];
         for(opportunity opp1:trigger.old){
             for(task tt:t){
             if(opp1.id==tt.whatid){
                 t.add(tt);
                 delete t;
                
             }
                 
             }
         }
}
}

i am getting the following error:
Illegeal assignment from list to list.

Please help..!!
hitesh90hitesh90
Hello Deepak,

Is there any class exist in your org with "task" name? may be that can be issue.

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
Kevin CrossKevin Cross
What are you trying to do?  I may be not getting the full logic but seems odd to add Task tt to List<Task> t then delete t in the same IF condition.
Kevin CrossKevin Cross
If the intention is to delete tasks associated to deleted Opportunity, here is an example that may help.  Just apply the concept to your Trigger code.  I figure if you give it a shot yourself, it will help with understanding.  You can post back if you have trouble.
 
List<Opportunity> opps = 
    [SELECT Id FROM Opportunity 
     WHERE Name = 'Test Opp' AND IsDeleted = true];
List<Task> tasks = [SELECT Id FROM Task WHERE whatId IN :opps];
delete tasks;

I put in fake selection criteria to protect the innocent (data), so just focus on the last two lines for what you need.
Amit Chaudhary 8Amit Chaudhary 8
IF you want to delete related task from opp then please update your code like  below
trigger deleteoppafter on Opportunity (after delete) 
{
	if(trigger.isafter && trigger.isdelete)
	{
		Set<ID> setOppId = new Set<ID>();
		for(opportunity opp1:trigger.old)
		{	
			setOppId.add(opp1.id);
		}
		
		List<Task>	lstTask=[select id,whatid from task where whatid in :setOppId];
		if(lstTask.size() > 0)
		{
			delete lstTask;
		}
		
	}
}

Let us know if this will help you
 
Deepak agarwal 9Deepak agarwal 9
Hello hitesh,

No there is no class by name task,but i am confused that class cannot be created in salesforce right??only objects can be
Deepak agarwal 9Deepak agarwal 9
Hello amit,
Thank you very much for the help.. But iam getting the same error. MIght be there is a problem in my org,code is fine.
Tell me if you come across any other help.Also sometimes iam getting the error like 'whatid' doesnot exists in tasks.
Deepak agarwal 9Deepak agarwal 9
Hello kevin,
My intention is to delete all actvities associated with the opportunites.(using trigger event after delete).
Deepak agarwal 9Deepak agarwal 9
Hello hitesh,
thanks for the help.Apex class task was already existingin my org so it got cleared.thanks once again
 
hitesh90hitesh90
Welcome Deepak.. Please mark this "Solved".

Thank You,
Hitesh Patel