function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lawlaw 

Trigger problem

I am attemtping to use the  trigger.old  to compare the previous owner value to the new owner value.  However in the code below t.owner in null.

any assistance would be greatly appreciated

 

for (Task t : Trigger.new) {
system.debug('NEW OwnerID' + t.Owner);
if(t.Owner != null && System.Trigger.oldMap.get(t.id).Owner == t.Owner){

Map<Id, Contact> contacts = new Map<Id, Contact> ([Select Id, Phone, MobilePhone, Status__c, RecordTypeId, AccountId, LeadSource, Last_Comment__c
From Contact
Where Id IN :contactIds]);
Map<Id, Contact> desiredContacts = new Map<Id, Contact> ();
for (Contact c : contacts.values()) {

if (RecordType == '012U0000000L2TJIA0'&& c.Status__c == 'Prospect: Not Contacted' ) { //Call
c.Status__c = 'Prospect: Contacted';
desiredContacts.put(c.Id, c);

}else if (RecordType == '012U0000000XcyZIAS' && c.Status__c == 'Candidate: Qualified') { //Meeting
c.Status__c = 'Candidate: Meeting';
desiredContacts.put(c.Id, c);
//Meeting //Prospect
}
if (Trigger.isInsert) {
if (RecordType == '012U0000000XcyZIAS' && c.RecordTypeId == '012U0000000Y3ybIAC' && c.Status__c != 'Candidate: Qualified') { /// 02-12-2013 lreed...If user has not qualified lead show error message
trigger.new[0].adderror('You Must Qualify The Candidate Before Logging A Meeting!');

}else if (RecordType == '012U0000000XcyZIAS' && c.RecordTypeId == '012U0000000Y3ybIAC' && c.Status__c != 'Prospect: Contacted')
{ /// 02-12-2013 lreed...If user has not qualified lead show error message
trigger.new[0].adderror('Please Log a Call Before Qualifying The Candidate!');
}
}
}

hitesh90hitesh90

hi,

 

Try to use OwnerId instead of Owner in your trigger.

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

Neha LundNeha Lund

'OwnerId' should be used in place of 'Owner'

lawlaw

Hello and Thank You

 

Now I am receiving  "System.NullPointerException: Attempt to de-reference a null object: Trigger.CandidateStatusFlow: line 59, column 1"

 

The following is line 59. I believe it has something to do with "System.Trigger.oldMap.get(t.id).OwnerID"

 

"if(t.OwnerID != null && System.Trigger.oldMap.get(t.id).OwnerID == t.OwnerID){"

hitesh90hitesh90

Hi,

 

Add one more condition in this line.


"if(t.OwnerID != null && System.Trigger.oldMap.get(t.id).OwnerID != null && System.Trigger.oldMap.get(t.id).OwnerID == t.OwnerID){"

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

lawlaw

Still receiving the same error message

Neha LundNeha Lund

Event should not be insert if you are using trigger.oldMap

Neha LundNeha Lund

if(t.OwnerId != null && (trigger.isUpdate && System.Trigger.oldMap.get(t.id).OwnerId == t.OwnerId)){

lawlaw

Nesha

 

That is right!  After make this last change the error is gone, however the condition never evaluates to true.  I have verified that the t.OwnerId is not null.

However when I try to use system.debug to see th value of "System.Trigger.oldMap.get(t.id).OwnerId", I receive the null pointer error.