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
SubC4i-dev1SubC4i-dev1 

Issue with getSobjectType - Save error: Comparison arguments must be compatible types

Having trouble understanding why my code is giving me the error below.  I have a feeling it's obvious, but I'm baffled nonetheless.  Trying to use getsobjectype in my if statement to verify that the lead owner is a user (i.e. to exclude queues).


Save error: Comparison arguments must be compatible types: SOBJECT:Lead, Id

 

Trouble line of code:

 

if(l.Lead_Stage__c.contains('Engaged') && l.Status.contains('Team Contribution') && userMap.get(l.OwnerId).Profile.Name.contains('LDR')
&& l.OwnerId.getSobjectType()==user.sObjectType && oldMap.get(l.OwnerId) == LDRmanagerQueue.Id)

 

Rest of that section of code:

 

public static void updateLDRlead(List<Lead> newList, Map<Id,Lead> oldMap){
		
		List<Lead> leadsToBeProcess = new List<Lead>();
		
		for(Lead l: newList){
			
			Lead oldL = oldMap.get(l.Id);
			leadOwnerIds.add(l.ownerId);
			leadOwnerIds.add(oldL.ownerId);
			
			if(l.Meets_LDR_Process_Criteria__c == true && l.Remove_from_LDR_Program__c == false){
				//Add to list of leads currently in the LDR Program
				leadsToBeProcess.add(l);
				
				//Set Record Type
				l.RecordTypeId = LDRrecord.Id;
				
				//Set Status to Nurture when entering the program
				if(oldL.Meets_LDR_Process_Criteria__c == false && l.Meets_LDR_Process_Criteria__c == true){
					l.Status = 'Nurture';
				}
				
				//Default Inquiry/Nuture to Lead Development Queue
				if(l.Lead_Stage__c == 'Inquiry' && l.Status == 'Nurture'){
					l.OwnerId = LDRmanagerQueue.Id;
				}
				
				//Stage is Engaged, Status is Team Contribution, and Owner changes LDR Manager Queue --> LDR
				if(l.Lead_Stage__c.contains('Engaged') && l.Status.contains('Team Contribution') && userMap.get(l.OwnerId).Profile.Name.contains('LDR') 
				&& l.OwnerId.getSobjectType()==user.sObjectType && oldMap.get(l.OwnerId) == LDRmanagerQueue.Id){
				}
				
			}
		}
	}

 

Thanks in advance for any assistance!

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

I'd image that the last part gives the error, oldmap.get() will return a Lead as its defined as Map<id,lead> which you can't compare to an Id. (and I'm not really sure that this is really what you want as ownerId isn't going to be a lead anwyay.

 

oldMap.get(l.OwnerId) == LDRmanagerQueue.Id

All Answers

SuperfellSuperfell

I'd image that the last part gives the error, oldmap.get() will return a Lead as its defined as Map<id,lead> which you can't compare to an Id. (and I'm not really sure that this is really what you want as ownerId isn't going to be a lead anwyay.

 

oldMap.get(l.OwnerId) == LDRmanagerQueue.Id
This was selected as the best answer
SubC4i-dev1SubC4i-dev1
Thanks SimonF, I was looking at the wrong part of the code the whole time. And you're right, the issue is that I should have written it as oldMap.get(l.id).ownerId == ldrmanagerqueue.Id I am checking to make sure that the previous owner was a queue.

But I am trying to compare the current/new lead ownerId to make sure it is a user and not a queue.