You need to sign in to do that
Don't have an account?
Jason McCarthy 2
Apex Error
I am getting a System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!addContact}' in component <apex:commandButton> in page addcontacttojobopportunity: Class.AddContacttoJobOpptController.addContact: line 30, column 1
I am trying to figure out what this means and how to fix it. I want to be able to add multiple existing contacts to a job opportunity (Record type on Opportunities object)
Heres the code:
Error is in expression '{!addContact}' in component <apex:commandButton> in page addcontacttojobopportunity: Class.AddContacttoJobOpptController.addContact: line 30, column 1
I am trying to figure out what this means and how to fix it. I want to be able to add multiple existing contacts to a job opportunity (Record type on Opportunities object)
Heres the code:
public with sharing class AddContacttoJobOpptController { public Opportunity opp {get;set;} public Contact con {get;set;} public String selectedConId = ''; public String selectedOppId = ''; String selectedOpportunityID = null; public AddContacttoJobOpptController(){ opp = new Opportunity(); selectedOppId = Apexpages.currentPage().getParameters().get('aid'); } public Pagereference addContact(){ Set<String> conIdSet = new Set<String>(); selectedConId = Con.Candidate__c ; selectedOppId = Opp.JobOpportunity_Lookup__c ; if(selectedConId != null && selectedConId != ''){ for(Contact con : [select id from Contact where Candidate__c = :selectedOppId]){ conIdSet.add(con.id); } if(conIdSet.contains(selectedConId)){ apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'The selected contact is already added to the Job Opportunity. Please select another contact to add.'); apexpages.addmessage(msg); return null; } else{ Contact con = new Contact(id=selectedConId); update con; apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'The selected contact has been added to the Job Opportunity. Now you can select another contact to add.'); apexpages.addmessage(msg); return null; } } else{ apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select contact then click on Add Contact button.'); apexpages.addmessage(msg); return null; } } public Pagereference goBack(){ return new Pagereference('/'+selectedOppId); } }