• Lokanath Gowd Ediga
  • NEWBIE
  • 0 Points
  • Member since 2011
  • Techno-Functional Consultant

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello all,

I have a scenario,where Business Development Manager(BDM) will conduct promotions on company's products. The members attened for that promotions are added as Promotion members(PMM)
Promotion is Master object
Promotion member is child.

Call centre guys verifies each promotion by calling PMM's on their Mobile No's.
If verification status(this is a picklist with Suggestion,Complaint,Others) is Complaint, then a task has to be created for concerned BDM and a task for his Manager.

I have this functionality built already, but the problem is, the tasks are getting created two times instead of one.
that is it is creating 4 tasks instead of 2(one for BDm , one for Manager)

i am posting my code here

Class:

public class PromotionmemberTaskHandler{
  
    Public static void createPromotionTasks(Map<Id,Promotion_Member__c> mapTriggerNew,Map<Id,Promotion_Member__c> mapTriggerOld){
        Map<id,Id> mapUserIdVsMgrId = new Map<id,Id>();
        List<Task> lstTask = new List<Task>();
         
        for(user u :[Select id,email,ManagersId__c from User where isActive = true and ManagersId__c <> null]){
            mapUserIdVsMgrId.put(u.id, u.ManagersId__c);  
        }
        
        for(Promotion_Member__c p: mapTriggerNew.Values()){
            if(p.Verified__c = true && p.Verification_Status__c == 'Complaint' && p.Verification_Status__c <> mapTriggerOld.get(p.Id).Verification_Status__c){
                if(mapUserIdVsMgrId.containsKey(p.CreatedById)){
                 Task t = new task();
                  t.ownerid = p.CreatedById;
                 t.Call_Center_Comments__c = p.Call_Center_Remarks__c;
                        t.WhatId = p.id;
                        t.Suggestion__c = p.Suggestion__c;
                        t.Complaint__c = p.Complaints__c;
                        t.ActivityDate = system.today();
                        t.Priority = 'Normal';
                        t.Subject = 'PromotionMember Complaint';
                      
                       insert t;
                       Task t1 = new task();
                 t1.Call_Center_Comments__c = p.Call_Center_Remarks__c;
                  t1.ownerid = mapUserIdVsMgrId.get(p.CreatedById);
                        t1.WhatId = p.id;
                        t1.Suggestion__c = p.Suggestion__c;
                        t1.Complaint__c = p.Complaints__c;
                        t1.ActivityDate = system.today();
                        t1.Priority = 'Normal';
                        t1.Subject = 'PromotionMember Complaint';
                      
                       insert t1;
              
                }
            }
        }
     
    }
}


Trigger:

Trigger TaskCreatepromotionmember on Promotion_Member__c (before update) {  
  if(Trigger.isUpdate && Trigger.isBefore){
      PromotionmemberTaskHandler.createPromotionTasks(trigger.newMap,trigger.oldMap);   
    }                                     
}


I am unable to traceout what the error in this code, so im posting here for your help

Thanks in advance.
Hello all,

I have a scenario,where Business Development Manager(BDM) will conduct promotions on company's products. The members attened for that promotions are added as Promotion members(PMM)
Promotion is Master object
Promotion member is child.

Call centre guys verifies each promotion by calling PMM's on their Mobile No's.
If verification status(this is a picklist with Suggestion,Complaint,Others) is Complaint, then a task has to be created for concerned BDM and a task for his Manager.

I have this functionality built already, but the problem is, the tasks are getting created two times instead of one.
that is it is creating 4 tasks instead of 2(one for BDm , one for Manager)

i am posting my code here

Class:

public class PromotionmemberTaskHandler{
  
    Public static void createPromotionTasks(Map<Id,Promotion_Member__c> mapTriggerNew,Map<Id,Promotion_Member__c> mapTriggerOld){
        Map<id,Id> mapUserIdVsMgrId = new Map<id,Id>();
        List<Task> lstTask = new List<Task>();
         
        for(user u :[Select id,email,ManagersId__c from User where isActive = true and ManagersId__c <> null]){
            mapUserIdVsMgrId.put(u.id, u.ManagersId__c);  
        }
        
        for(Promotion_Member__c p: mapTriggerNew.Values()){
            if(p.Verified__c = true && p.Verification_Status__c == 'Complaint' && p.Verification_Status__c <> mapTriggerOld.get(p.Id).Verification_Status__c){
                if(mapUserIdVsMgrId.containsKey(p.CreatedById)){
                 Task t = new task();
                  t.ownerid = p.CreatedById;
                 t.Call_Center_Comments__c = p.Call_Center_Remarks__c;
                        t.WhatId = p.id;
                        t.Suggestion__c = p.Suggestion__c;
                        t.Complaint__c = p.Complaints__c;
                        t.ActivityDate = system.today();
                        t.Priority = 'Normal';
                        t.Subject = 'PromotionMember Complaint';
                      
                       insert t;
                       Task t1 = new task();
                 t1.Call_Center_Comments__c = p.Call_Center_Remarks__c;
                  t1.ownerid = mapUserIdVsMgrId.get(p.CreatedById);
                        t1.WhatId = p.id;
                        t1.Suggestion__c = p.Suggestion__c;
                        t1.Complaint__c = p.Complaints__c;
                        t1.ActivityDate = system.today();
                        t1.Priority = 'Normal';
                        t1.Subject = 'PromotionMember Complaint';
                      
                       insert t1;
              
                }
            }
        }
     
    }
}


Trigger:

Trigger TaskCreatepromotionmember on Promotion_Member__c (before update) {  
  if(Trigger.isUpdate && Trigger.isBefore){
      PromotionmemberTaskHandler.createPromotionTasks(trigger.newMap,trigger.oldMap);   
    }                                     
}


I am unable to traceout what the error in this code, so im posting here for your help

Thanks in advance.