You need to sign in to do that
Don't have an account?
Help reading APEX class error -
A vendor created the APEX class, and also a monitor option for errors...great in theory, except i am not sure what the error means or what i need to do to fix it.
Here is the ERROR:
Visualforce Page: /apex/CTIScreenPop
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.CTIScreenPopCtlr.initConfirmContactInformation: line 25, column 1
Here is the APEX Class:
public with sharing class CTIScreenPopCtlr {
public PHSSModel.ConstituentDetail constituentDetail {get; set;}
public Contact confirmContactProxy {get; set;}
public String phone { get; set; }
public String formattedPhone {get; set;}
public PHSSModel.ConstituentSearchCriteria constituentSearchForm {get; set;}
public PHSSModel.ConstituentSearchResultWrapper constituentSearchResultsWrapper {get; set;}
public List<PHSSModel.ConstituentSearchResult> constituentSearchResults {get; set;}
public PHSSIntegrationService phssIntegrationService {get; set;}
public Contact qcContactProxy {get; set;}
public String pageTitle {get; set;}
public String selectedConstituentId {get; set;}
public String selectedContactId {get; set;}
public String selectedManagedLearningFlag {get; set;}
public Boolean showPhoneIcon {get; set;}
public void initConfirmContactInformation() {
confirmContactProxy = new Contact();
try{
constituentDetail = phssIntegrationService.doConstituentDetails( selectedConstituentId );
}catch(Exception e){
ExLog.log(e); // catch Exception Vinayak
}
confirmContactProxy.firstName = constituentDetail.FirstName;
confirmContactProxy.lastName = constituentDetail.LastName;
confirmContactProxy.mailingStreet = constituentDetail.ARCBestAddressLine1;
confirmContactProxy.mailingCity = constituentDetail.ARCBestCity;
confirmContactProxy.mailingState = constituentDetail.ARCBestState ;
confirmContactProxy.mailingPostalCode = constituentDetail.ARCBestZip ;
confirmContactProxy.email = constituentDetail.ARCBestEmailAddress;
confirmContactProxy.phone = constituentDetail.ARCBestPhone;
}
public PageReference Confirm() {
Account newAccount = new Account();
Contact newContact = new Contact();
newAccount.name = confirmContactProxy.LastName;
newAccount.billingStreet = confirmContactProxy.MailingStreet;
newAccount.billingCity = confirmContactProxy.MailingCity;
newAccount.billingState = confirmContactProxy.MailingState;
newAccount.billingPostalCode = confirmContactProxy.MailingPostalCode;
Savepoint sp = Database.setSavePoint();
try {
Insert newAccount;
} catch (Exception ex) {
ApexPages.addMessages(ex);
ExLog.log(ex); // catch Exception Vinayak
return null;
}
// get the auto generated account number
Account accountJustCreated = [SELECT id,
Name,
Account_Auto_Number__c
FROM Account
WHERE id = :newAccount.id
LIMIT 1];
accountJustCreated.name = AccountService.constructAccountName( confirmContactProxy.lastName, accountJustCreated.Account_Auto_Number__c );
update accountJustCreated;
newContact.Master_Constituent_ID__c = constituentDetail.ConstituentId;
newContact.firstName = confirmContactProxy.FirstName;
newContact.lastName = confirmContactProxy.LastName;
newContact.email = confirmContactProxy.email;
newContact.phone = confirmContactProxy.Phone;
newContact.mailingStreet = confirmContactProxy.mailingStreet;
newContact.mailingCity = confirmContactProxy.mailingCity;
newContact.mailingState = confirmContactProxy.mailingState;
newContact.mailingPostalCode = confirmContactProxy.mailingPostalCode;
newContact.email = confirmContactProxy.email;
newContact.title = constituentDetail.Title ;
newContact.Saba_Person_Id__c = constituentDetail.SabaPersonId.left(20) ;
if (constituentDetail.InstructorFlag == 'Yes') {
newContact.Contact_Type__c = 'Instructor';
}
newContact.AccountId = newAccount.id;
try {
Insert newContact;
} catch(Exception ex) {
ApexPages.addMessages(ex);
ExLog.log(ex); // catch Exception Vinayak
return null;
}
PageReference pageRef = new PageReference('/' + newContact.id);
return pageRef;
}
public pageReference cancelConfirmContactInformation() {
PageReference pageRef = Page.CTIScreenPop;
return pageRef;
}
public PageReference searchForPhone() {
try{
if (phone != '' && phone != null ) {
constituentSearchResultsWrapper = phssIntegrationService.doPhoneSearch( formattedPhone );
if (constituentSearchResultsWrapper != null) {
constituentSearchResults = constituentSearchResultsWrapper.constituentSearchResults;
} else {
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.INFO, 'No matching customers were found...');
ApexPages.addMessage(msg);
}
}
}catch(Exception e){
ExLog.log(e); // catch Exception Vinayak
}
return null;
}
public PageReference searchForConstituent() {
// clear out old results
constituentSearchResults.clear();
if (constituentSearchForm.Phone != '') {
constituentSearchForm.Phone = formatPhone(constituentSearchForm.phone);
}
// trim leading and trailing spaces from all search fields
constituentSearchForm.City = constituentSearchForm.City.trim();
constituentSearchForm.EmailAddress = constituentSearchForm.EmailAddress.trim();
constituentSearchForm.FirstName = constituentSearchForm.FirstName.trim();
constituentSearchForm.LastName = constituentSearchForm.LastName.trim();
constituentSearchForm.State = constituentSearchForm.State.trim();
constituentSearchForm.Zip = constituentSearchForm.Zip.trim();
try{
constituentSearchResultsWrapper = phssIntegrationService.doGeneralSearch( constituentSearchForm );
if (constituentSearchResultsWrapper != null) {
constituentSearchResults = constituentSearchResultsWrapper.constituentSearchResults;
} else {
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.INFO, 'No matching customers were found...');
ApexPages.addMessage(msg);
}
}catch(Exception e){
ExLog.log(e); // catch Exception Vinayak
}
return null;
}
public PageReference selectConstituent() {
PageReference redirectTo;
//try to find a match is SFDC
Contact existingContact;
Boolean isFound = false;
// find contact in SFDC by Master Constituent Id
if (selectedConstituentId != null) {
try {
existingContact = [Select id, name FROM contact WHERE master_constituent_id__c = :selectedConstituentId LIMIT 1];
if (existingContact != null) {
isFound = true;
}
} catch (Exception ex) {ExLog.log(ex); } // catch Exception Vinayak
}
// find by managed learning flag and contact id
if ( !isFound ) {
if ( selectedManagedLearningFlag == 'Yes' && selectedContactId != null ) {
try {
existingContact = [Select id, name FROM contact WHERE id = :selectedContactId LIMIT 1];
if (existingContact != null) {
isFound = true;
}
} catch(Exception ex) {ExLog.log(ex); } // catch Exception Vinayak
}
}
if (isFound) {
redirectTo = new PageReference('/'+ existingContact.id);
} else {
redirectTo = Page.ConfirmContactInformation;
}
return redirectTo;
}
public PageReference QuickCreateConstituent() {
Account newAccount = new Account();
newAccount.Name = qcContactProxy.lastName;
newAccount.billingStreet = qcContactProxy.mailingStreet;
newAccount.billingCity = qcContactProxy.mailingCity;
newAccount.billingState = qcContactProxy.mailingState; // required by validation rule
newAccount.billingPostalCode = qcContactProxy.mailingPostalCode;
Savepoint sp = Database.setSavePoint();
try {
insert newAccount;
} catch (Exception ex) { ApexPages.addMessages(ex); ExLog.log(ex); return null; } // catch Exception Vinayak
// get the auto generated account number
Account accountJustCreated = [SELECT id, Name, Account_Auto_Number__c FROM Account WHERE id = :newAccount.id LIMIT 1];
accountJustCreated.name = AccountService.constructAccountName( qcContactProxy.lastName, accountJustCreated.Account_Auto_Number__c );
update accountJustCreated;
Contact newContact = new Contact();
newContact.firstName = qcContactProxy.firstName;
newContact.lastName = qcContactProxy.lastName;
newContact.email = qcContactProxy.email;
newContact.phone = qcContactProxy.phone;
newContact.mailingStreet = qcContactProxy.mailingStreet;
newContact.mailingPostalCode = qcContactProxy.mailingPostalCode;
newContact.mailingCity = qcContactProxy.mailingCity;
newContact.mailingState = qcContactProxy.mailingState;
newContact.AccountId = newAccount.id;
try {
insert newContact;
} catch (Exception ex) {
ApexPages.addMessages(ex);
Database.rollback(sp);
return null;
}
PageReference contactPageRef = new PageReference('/' + newContact.id);
contactPageRef.setRedirect(true);
return contactPageRef;
}
public CTIScreenPopCtlr() {
phone = ApexPages.currentPage().getParameters().get('ANI');
phssIntegrationService = new PHSSIntegrationService();
constituentSearchResults = new List<PHSSModel.ConstituentSearchResult>();
qcContactProxy = new Contact();
constituentSearchForm = new PHSSModel.ConstituentSearchCriteria();
if (phone != '' && phone != null ) {
formattedPhone = formatPhone(phone);
pageTitle = 'Caller\'s Phone Number';
showPhoneIcon = true;
} else {
pageTitle = 'Search For A Customer';
showPhoneIcon = false;
}
}
private String formatPhone(String phone) {
// phone is passed in as numbers only and is pre-pended with '1'
String formattedPhone;
// remove all non numbers
phone = phone.replaceAll('\\D','');
phone = phone.right(10);
formattedPhone = '(' + phone.left(3) + ') ' + phone.mid(3, 3) + '-' + phone.right(4);
return formattedPhone;
}
}
Line 25 is bolded.
Any help would be GREATLY appreciated!!
That error means that ContituentDetail is null, so when you try to access a property (ie: FirstName) you get an error.
You should check for null in the initConfirmContactInformation method. ie: