You need to sign in to do that
Don't have an account?
J!GS
Help In System.NullPointerException: Attempt to de-reference a null object: Trigger
trigger CreateTaskWhenNewLeadGenerate on Lead (after insert) {
Set<Id> LdIdSet = new Set<Id>();
if(Trigger.isAfter && Trigger.isInsert) {
List<Lead> LdList = [ SELECT Id,Name,OwnerId,Company,Email, Phone,pi__comments__c,Leasing_agent__c,Create_Leasing_Call_Task__c,Lead_Property_Of_Interest__c FROM Lead WHERE Id IN : LdIdSet];
Map<Id,List<Lead>> LIdLdListMap = new Map<Id,List<Lead>>();
List<Task> insTskList;
Task newTsk ;
for ( BP_Property__c Prop:[Select Id,Name,IS_ACTIVE__c,Leasing_agent__c from BP_Property__c])
{
// LdList = LIdLdListMap.get(Prop) ;
for ( Lead Ld : Trigger.New ){
LdIdSet.add ( Ld.Id );
if ( Trigger.NewMap.get ( Ld.Id ).Create_Leasing_Call_Task__c && ! Ld.Create_Leasing_Call_Task__c ){
//Ld.Create_Leasing_Call_Task__c = true;
LdList = LIdLdListMap.get( Ld.Id ) ;
if ( LdList == null || LdList.size() == 0 )
continue;
if(Ld.Lead_Property_Of_Interest__c == null){
if(Ld.Leasing_Agent__c == null){
}
else{
newTsk = new Task();
newTsk.Subject = 'PC-Leasing Call';
newTsk.OwnerId = Ld.Id;
newTsk.Leasing_Agent_ID__c = 'a0MG000000XkQFc';
insTskList.add ( newTsk );
}
}
}else if(Ld.Lead_Property_Of_Interest__c != null && Ld.Leasing_Agent__c != null )
{ prop.IS_ACTIVE__c = true;
prop.Leasing_Agent__r.IS_ACTIVE__c = true;
}
else{
newTsk = new Task();
newTsk.Subject = 'LAInitial-Leasing call';
newTsk.OwnerId = Ld.Owner_ID__c;
newTsk.WhoId =Ld.Id ;
NewTsk.Leasing_Agent__c = Ld.Leasing_Agent__c ;
insTskList.add ( newTsk );
}
}
}
insert newTsk;
}
}
Set<Id> LdIdSet = new Set<Id>();
if(Trigger.isAfter && Trigger.isInsert) {
List<Lead> LdList = [ SELECT Id,Name,OwnerId,Company,Email, Phone,pi__comments__c,Leasing_agent__c,Create_Leasing_Call_Task__c,Lead_Property_Of_Interest__c FROM Lead WHERE Id IN : LdIdSet];
Map<Id,List<Lead>> LIdLdListMap = new Map<Id,List<Lead>>();
List<Task> insTskList;
Task newTsk ;
for ( BP_Property__c Prop:[Select Id,Name,IS_ACTIVE__c,Leasing_agent__c from BP_Property__c])
{
// LdList = LIdLdListMap.get(Prop) ;
for ( Lead Ld : Trigger.New ){
LdIdSet.add ( Ld.Id );
if ( Trigger.NewMap.get ( Ld.Id ).Create_Leasing_Call_Task__c && ! Ld.Create_Leasing_Call_Task__c ){
//Ld.Create_Leasing_Call_Task__c = true;
LdList = LIdLdListMap.get( Ld.Id ) ;
if ( LdList == null || LdList.size() == 0 )
continue;
if(Ld.Lead_Property_Of_Interest__c == null){
if(Ld.Leasing_Agent__c == null){
}
else{
newTsk = new Task();
newTsk.Subject = 'PC-Leasing Call';
newTsk.OwnerId = Ld.Id;
newTsk.Leasing_Agent_ID__c = 'a0MG000000XkQFc';
insTskList.add ( newTsk );
}
}
}else if(Ld.Lead_Property_Of_Interest__c != null && Ld.Leasing_Agent__c != null )
{ prop.IS_ACTIVE__c = true;
prop.Leasing_Agent__r.IS_ACTIVE__c = true;
}
else{
newTsk = new Task();
newTsk.Subject = 'LAInitial-Leasing call';
newTsk.OwnerId = Ld.Owner_ID__c;
newTsk.WhoId =Ld.Id ;
NewTsk.Leasing_Agent__c = Ld.Leasing_Agent__c ;
insTskList.add ( newTsk );
}
}
}
insert newTsk;
}
}
Looking again, I think the error is comimg from this line It looks the LdIdSet is just never set to a value, it is simply initialzed to LdIdSet = new Set<Id>();
All Answers
Looking again, I think the error is comimg from this line It looks the LdIdSet is just never set to a value, it is simply initialzed to LdIdSet = new Set<Id>();
Hi, Please check this code I think you have to change code in 1st three lines
Set<Id> LdIdSet = new Set<Id>();
LdIdSet = Trigger.newMap.keySet();
List<Lead> LdList = [ SELECT Id,Name,OwnerId,Company,Email, Phone,pi__comments__c,Leasing_agent__c,Create_Leasing_Call_Task__c,Lead_Property_Of_Interest__cFROM Lead WHERE Id IN : LdIdSet];