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
kevoharakevohara 

Problem with Lead.sObjectType

I am trying to develop a VF controller extension that works with Leads and Opportunities.  In my constructor I am checking the sObjectType of the standard controller then handling everything else according to whether its a Lead or an Opportunity.  For some reason, I am getting an "invalid field Lead.sObjectType" error when saving in the IDE.  I get no such error with the Opportunity.sObjectType.  How is this possible?

 

 

public class EventsController {
	
	private final Lead lead;
	private final Opportunity opp;	
	
	public EventsController(ApexPages.StandardController controller) {
		
		
		sObject record = controller.getRecord();
		Schema.sObjectType objType = record.getSObjectType();
		
		if(objType == Lead.sObjectType) {
			
			//Process the lead 
					
		} else if (objType == Opportunity.sObjectType) {
			
			//Process the opportunity
					
		}
		
					
	}

}

 

Again, only the Lead.sObjectType is giving me problems.  I tested it with only the Opportunity.sObjectType and it works fine.

 

Any suggestions?

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
joshbirkjoshbirk

It's the case insensitivy doing a figure eight, try mylead instead of lead...

 

 

public EventsController(ApexPages.StandardController controller) {
		this.mylead = (Lead)controller.getRecord();
        
        if(mylead.getSObjectType() == Lead.sObjectType) {
        	System.debug('Just a test');
        }
	}

 

 

 

All Answers

joshbirkjoshbirk

It's the case insensitivy doing a figure eight, try mylead instead of lead...

 

 

public EventsController(ApexPages.StandardController controller) {
		this.mylead = (Lead)controller.getRecord();
        
        if(mylead.getSObjectType() == Lead.sObjectType) {
        	System.debug('Just a test');
        }
	}

 

 

 

This was selected as the best answer
kevoharakevohara

D'oh!

 

How insensitive of Apex to do that to me!