Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

Thanks!

share|improve this question
add comment

2 Answers

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 Kumar Jan 16 '13 at 18:02
1  
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
add comment

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
add comment

Your Answer

 
discard

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.