Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd appreciate it if someone "in the know" could verify this and let me know if there is a way to RECTIFY this.

  1. A lead is created. A task is linked to that Lead.

  2. The lead is converted to an Account with Opportunity. The task is linked to the Opportunity and Account (apparently the Opp is the parent and the Account is "only" the grandparent).

  3. The Opp is DELETED. The Task ends up deleted WITH the Opp.

This is not ideal in our scenario. We would like to KEEP the Task when the Opp is deleted. Is there a canned mechanism that handles such needs?


share|improve this question
up vote 2 down vote accepted

There is no built-in mechanism that addresses this. You will need to create a trigger on delete on Opportunity that checks if that opportunity has related tasks and re-parents them to the account. The following helper method should work for you:

public static void ReparentTasks(Map<Id, Opportunity> mapNew)
    for(list<Task> tasks : [select Id, whatID from Task where whatId in :mapNew.keyset()])
        for(Task t : tasks) t.whatID = mapNew.get(t.WhatID).AccountID;
        update tasks;
share|improve this answer
Just a heads up looks like update statement is in for loop.So may be declaring a list and moving update out of for loop will make solution robust! – Mohith Shrivastava Jan 16 '13 at 18:02
That was intentional. There could be many tasks relating to opportunities so I'm using the query/querymore pattern. – Greg Grinberg Jan 16 '13 at 18:20

You can also create a trigger on Task object so that when a task is initially created , it will automatically be attached to related Account.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.