You need to sign in to do that
Don't have an account?
Nick Keehan
Attempt to de-reference a null object - Wont Create Opportunity on Account
Hi Guys.
The below code will create an account fine, however it will not allow me to add an opportunity to the account with the error "System.NullPointerException: Attempt to de-reference a null object".
It is erroring at Opportunity.name (first line or opp)
Turned debug on however still cant see whats causing this. any ideas?
Apex Class
The below code will create an account fine, however it will not allow me to add an opportunity to the account with the error "System.NullPointerException: Attempt to de-reference a null object".
It is erroring at Opportunity.name (first line or opp)
Turned debug on however still cant see whats causing this. any ideas?
Apex Class
public class CreatingWizard{ Contact contact; Account account; Opportunity opportunity; OpportunityContactRole role; public Contact getContact() { if(contact == null) contact = new Contact(); return contact;} public Account getAccount() { if(account == null) account = new Account(); return account;} public Opportunity getOpportunity() { if(opportunity == null) opportunity = new Opportunity(); return opportunity;} public OpportunityContactRole getRole() { if(role == null) role = new OpportunityContactRole(); return role;} public PageReference createcustomer() { contact.LastName = Account.LastName; contact.FirstName = Contact.FirstName; insert contact; account.LastName = Account.LastName; account.FirstName = Contact.FirstName; account.Phone = Account.Phone; account.PersonMobilePhone = Account.PersonMobilePhone; account.ShippingStreet = Account.ShippingStreet; account.RecordTypeID = '012200000000iKt'; account.Customer_Data_Source__c = 'https://c.cs86.visual.force.com/apex/accoppwizard'; insert account; opportunity.Name = 'Oneview Resign/Upgrade'; opportunity.CampaignId = '7017E0000004srD'; opportunity.CloseDate = system.today(); opportunity.StageName = 'Closed Won'; opportunity.accountId = '0017E00000IadeE'; insert opportunity; role.opportunityId = opportunity.id; role.contactId = contact.id; insert role; PageReference newPage = New PageReference('/'+opportunity.id); newPage.setRedirect(true); return newPage; return null; } }
I believe you will need to post the VF page to debug this issue. From you apex class i can see that the instantiation of the Account Contact and Opportunity is happening as part of a getter method. The method CreateCustomer I believe is executing on a click of a buton or link.
Please ensure that the Opportunity is also instantiated via getter setter on your VF page before this button is clicked.
As an alternative you can instantiate your variables in constructor