• Ishan Singh 4
  • NEWBIE
  • 30 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 30
    Questions
  • 14
    Replies
I have created a field(lookup on account) on lead object to select account name. What I want to do is when I select a particular account name in that lookup field then 2 fields(let it be X and Y) which are on account their data should come in leads 2 fields(Lets say A and B) .  

Currently I am using duplicate rule but through it I am not able to send email. If you are suggesting for a process builder then please mention the criteria to trigger it.
The Matching rules are:
Last name
Phone number  

I have a trigger which works on (after insert, after update) 

but due to some reason the task owner is not assigned when task is created but when I update the task it's owner name populates. I can not do any changes in existing code beacuse it's too complex. So is there any way by which I can update a task owner when 'Round_Robin_ID__c ' field = 1 to XYZ  

I am trying this   -    newTask.Lead__c.RR_ID__c == 2

newTask = new task[on task object]
RR_ID__c = custom field on lead object 

Error - Variable does not exist: newTask.Lead__c
There is a custom field name - RR id on lead object.
I want to access that RR id field in my apex class from Task object 
The formula for due date is correct. This problem is coming when a lead is inserted on monday and according to formula of due date when a lead is entered on sunday, the task generated due date should be on next day.  
 for(Lead l: scope)
        {
            
            if(l.State!=''){ //State is not empty
                l.State__c =l.State__c;
            }else{    //State is empty
                l.State__c ='Default';}
            
            
            l.Age__c = l.Current_Age__c;
            
        }
        update scope;
    }
global class BirthdayCard implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc)
     {
        return Database.getQueryLocator([SELECT OwnerId,DOB_Formula__c,Id,Possible_Followup_Date__c FROM Lead WHERE DOB_Formula__c =  NEXT_N_DAYS:7 AND Possible_Followup_Date__c != null]);
    }
    global void execute(Database.BatchableContext bc, List<Lead> scope)
    { 
        List<Task> listOfTask = new list<Task>();
        
        for(Lead l : scope)
        {
            Task B = new Task();
            B.Subject= 'Send Birthday Card';
            B.ActivityDate = date.today();
            B.OwnerId = l.OwnerId;
            B.WhoId=l.Id;
            listOfTask.add(B);
 
batchClass

global class BirthdayCard implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc)
     {
        return Database.getQueryLocator([SELECT dateOfBirth__c,Id,Possible_Followup_Date__c FROM Lead WHERE dateOfBirth__c =  NEXT_N_DAYS:7 AND Possible_Followup_Date__c != null]);
    }
    global void execute(Database.BatchableContext bc, List<Task> scope)
    {
        for(Task l : scope)
        {
            Task B = new Task();
            B.Subject= 'Send Birthday Card';
            B.ActivityDate = date.today();
            B.OwnerId = l.OwnerId;
            B.WhoId=l.Id;
            
                   
       }
        insert scope;
    }
    global void finish(Database.BatchableContext bc){}
    
}

testClass:

@isTest
public class BirthdayCardTest{
    @isTest
    public static void BirthdayCard(){
        List<Lead> leadList = new List<Lead>();
        {
            Lead ld = new Lead();
            ld.lastname = 'test';
            ld.dateOfBirth__c = date.today().addDays(7);
            ld.Status = 'Unqualified';
            ld.State__c='Test';
            ld.Policy_DB_Amount__c=100000;
            ld.Company='Mirketa';
            ld.Possible_Followup_Date__c=date.today()
            
           leadList.add(ld);  
        }
        insert leadList;
        Test.startTest();
        Database.executeBatch(new BirthdayCard());
        Test.stopTest();
    }
}