- Home
- Technical Library
- Boards
- Cookbook
- Code Share
- Blogs
- Partners
-
More
-
Services
- Training & Certification
- Support
-
Galleries
- Force.com Sites Gallery
- Chatter Challenge Entries
-
Other Web Sites
- Salesforce.com
- Database.com
- AppExchange
- CRM Community
-
Discussions
- Announcements
- General Development
- Schema Development
- New to Cloud Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules Discussion
- Security
- Mobile
- Force.com Sites
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby Development
- Adobe Flash Builder for Force.com
- Desktop Integration
- REST API Integration
- Streaming API
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- Excel Connector
- AJAX Toolkit & S-controls
- Force.com Builder & Native Apps
- AppExchange Directory & Packaging
- Force.com Labs Projects
- Open Source
- Site.com
- Jobs Board - Administrators
- Jobs Board - Developers
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- System.NullPointerException: Attempt to de-referen...
turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
System.Nul lPointerEx ception: Attempt to de-referen ce a null object
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-10-2008 02:12 AM
Hi All,
I am getting follwoing errors while doing the batch upload on opportunity obj.
Developer script exception from DuplicatelineOpptychange : DuplicatelineOpptychange: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Class.DuplicatelineOpptyUpdate.opptyupdate: line 134, column 99
Here is my code:
public static Opportunity[] opptyupdate(Opportunity[] opptyIds){
System.debug('In opptyupdate public method of the UpdateOpptypkg class');
System.debug('Processing ' + opptyIds.size() + ' opportunities');
//Get the partners name related to the changed opportunity
OpportunityPartner[] partner = [select AccountTo.Name, OpportunityId From OpportunityPartner WHERE OpportunityId in :opptyIds ];
//Get the Tech & Service name related to the changed oppty
OpportunityLineItem[] technologyentry = [Select PricebookEntry.ProductCode, PricebookEntry.Name, Mix__c , OpportunityId From OpportunityLineItem where OpportunityId in: opptyIds order by Mix__c DESC];
Integer x1 =0;
Integer y1 =0;
for(x1=0;x1< opptyIds.size();x1++)
{
String newPartnerString ='';
for(y1=0; y1<partner.size();y1++)
{
//THIS LOOP WILL FIND ALL THE PARTNERS RELATED TO THE EXISTING CHANGED OPPTY AND UPDATE THE PARTNER MERGE FIELD
if(partner[y1].OpportunityId == opptyIds[x1].Id && partner[y1].AccountToId != opptyIds[x1].AccountId && (opptyIds[x1].RecordTypeId == '0123000000003ykAAA' || opptyIds[x1].RecordTypeId == '012300000000CDLAA2') )
{
if(newPartnerString == '')
{ newPartnerString += partner[y1].AccountTo.Name ;
}
else
{ newPartnerString = newPartnerString + ';' + partner[y1].AccountTo.Name;
}
}
}
opptyIds[x1].Partners_Merge_Field__c = newPartnerString; //Set the new value of the merge field
String newservice1 ='';
String newservice2 ='';
Integer q;
for(q=0; q<technologyentry.size();q++)
//THIS LOOP WILL FIND ALL THE TECHNOLOGY AND SERVICE RELATED TO THE EXISTING CHANGED OPPTY AND UPDATE THE TECHNOLOGY AND SERVICE MERGE FIELD
{
if(technologyentry[q].OpportunityId == opptyIds[x1].Id )
{
if (technologyentry[q].PricebookEntry.ProductCode == 'Technology'&& (opptyIds[x1].RecordTypeId == '0123000000003ykAAA' || opptyIds[x1].RecordTypeId == '012300000000CDLAA2'))
{ if(newservice1 == '')
{ newservice1 += technologyentry[q].PricebookEntry.Name + ' (' + technologyentry[q].Mix__c.intValue()+ ')';
}
else
{ newservice1 = newservice1 + ';' + technologyentry[q].PricebookEntry.Name + ' (' + technologyentry[q].Mix__c.intValue() + ')';
}
}
opptyIds[x1].Technology_Merge_Field__c = newservice1; //Set the new value of the merge field
if (technologyentry[q].PricebookEntry.ProductCode == 'Service'&& (opptyIds[x1].RecordTypeId == '0123000000003ykAAA' || opptyIds[x1].RecordTypeId == '012300000000CDLAA2'))
{ if(newservice2 == '')
{ newservice2 += technologyentry[q].PricebookEntry.Name + ' (' + technologyentry[q].Mix__c.intValue() + ')';
}
else
{ newservice2 = newservice2 + ';' + technologyentry[q].PricebookEntry.Name + ' (' + technologyentry[q].Mix__c.intValue() + ')';
}
}
opptyIds[x1].Service_Merge_Field__c = newservice2; //Set the new value of the merge field
} //if for opptyid comparision with tech & service (opptyid)
} //for tech loop
}//for loop for oppty
Return opptyIds ;
}
}
System.debug('In opptyupdate public method of the UpdateOpptypkg class');
System.debug('Processing ' + opptyIds.size() + ' opportunities');
//Get the partners name related to the changed opportunity
OpportunityPartner[] partner = [select AccountTo.Name, OpportunityId From OpportunityPartner WHERE OpportunityId in :opptyIds ];
//Get the Tech & Service name related to the changed oppty
OpportunityLineItem[] technologyentry = [Select PricebookEntry.ProductCode, PricebookEntry.Name, Mix__c , OpportunityId From OpportunityLineItem where OpportunityId in: opptyIds order by Mix__c DESC];
Integer x1 =0;
Integer y1 =0;
for(x1=0;x1< opptyIds.size();x1++)
{
String newPartnerString ='';
for(y1=0; y1<partner.size();y1++)
{
//THIS LOOP WILL FIND ALL THE PARTNERS RELATED TO THE EXISTING CHANGED OPPTY AND UPDATE THE PARTNER MERGE FIELD
if(partner[y1].OpportunityId == opptyIds[x1].Id && partner[y1].AccountToId != opptyIds[x1].AccountId && (opptyIds[x1].RecordTypeId == '0123000000003ykAAA' || opptyIds[x1].RecordTypeId == '012300000000CDLAA2') )
{
if(newPartnerString == '')
{ newPartnerString += partner[y1].AccountTo.Name ;
}
else
{ newPartnerString = newPartnerString + ';' + partner[y1].AccountTo.Name;
}
}
}
opptyIds[x1].Partners_Merge_Field__c = newPartnerString; //Set the new value of the merge field
String newservice1 ='';
String newservice2 ='';
Integer q;
for(q=0; q<technologyentry.size();q++)
//THIS LOOP WILL FIND ALL THE TECHNOLOGY AND SERVICE RELATED TO THE EXISTING CHANGED OPPTY AND UPDATE THE TECHNOLOGY AND SERVICE MERGE FIELD
{
if(technologyentry[q].OpportunityId == opptyIds[x1].Id )
{
if (technologyentry[q].PricebookEntry.ProductCode == 'Technology'&& (opptyIds[x1].RecordTypeId == '0123000000003ykAAA' || opptyIds[x1].RecordTypeId == '012300000000CDLAA2'))
{ if(newservice1 == '')
{ newservice1 += technologyentry[q].PricebookEntry.Name + ' (' + technologyentry[q].Mix__c.intValue()+ ')';
}
else
{ newservice1 = newservice1 + ';' + technologyentry[q].PricebookEntry.Name + ' (' + technologyentry[q].Mix__c.intValue() + ')';
}
}
opptyIds[x1].Technology_Merge_Field__c = newservice1; //Set the new value of the merge field
if (technologyentry[q].PricebookEntry.ProductCode == 'Service'&& (opptyIds[x1].RecordTypeId == '0123000000003ykAAA' || opptyIds[x1].RecordTypeId == '012300000000CDLAA2'))
{ if(newservice2 == '')
{ newservice2 += technologyentry[q].PricebookEntry.Name + ' (' + technologyentry[q].Mix__c.intValue() + ')';
}
else
{ newservice2 = newservice2 + ';' + technologyentry[q].PricebookEntry.Name + ' (' + technologyentry[q].Mix__c.intValue() + ')';
}
}
opptyIds[x1].Service_Merge_Field__c = newservice2; //Set the new value of the merge field
} //if for opptyid comparision with tech & service (opptyid)
} //for tech loop
}//for loop for oppty
Return opptyIds ;
}
}
Can any one suggest why this is happening. This is really urgent to be solved. Any help would be appericiated.
Thanks,
Solved! Go to Solution.
Re: System.Nul lPointerEx ception: Attempt to de-referen ce a null object
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-10-2008 04:19 PM
Hi gopivyas,
Well, that's a lot of code. Somewhere in there you are making an assumption about the existence of a record or a field and that assumption is incorrect. You will need to make sure that the values you are working with are not null. Sometimes this can happen if you are operating on a field from a record returned from a SOQL statement, but did not include the field in the select list. There are many other reasons why this would happen as well. I would check any value that you are evaluating to ensure that it is not null.
Cheers
Well, that's a lot of code. Somewhere in there you are making an assumption about the existence of a record or a field and that assumption is incorrect. You will need to make sure that the values you are working with are not null. Sometimes this can happen if you are operating on a field from a record returned from a SOQL statement, but did not include the field in the select list. There are many other reasons why this would happen as well. I would check any value that you are evaluating to ensure that it is not null.
Cheers
Re: System.Nul lPointerEx ception: Attempt to de-referen ce a null object
[ Edited ]
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
06-24-2008 09:26 AM - last edited on 06-24-2008 09:47 AM
In your intial query, you should also exclude null values in the fields. Something like this:
OpportunityLineItem[] technologyentry = [Select PricebookEntry.ProductCode, PricebookEntry.Name, Mix__c , OpportunityId From OpportunityLineItem where OpportunityId in: opptyIds
and <possible null field> != null
order by Mix__c DESC];
Also, if/when you use relationships in your query, do it once for the parent and once for the child.
Message Edited by gApps on 06-24-2008 09:47 AM
Message Edited by gApps on 06-24-2008 09:47 AM
OpportunityLineItem[] technologyentry = [Select PricebookEntry.ProductCode, PricebookEntry.Name, Mix__c , OpportunityId From OpportunityLineItem where OpportunityId in: opptyIds
and <possible null field> != null
order by Mix__c DESC];
Also, if/when you use relationships in your query, do it once for the parent and once for the child.
Message Edited by gApps on 06-24-2008 09:47 AM
Message Edited by gApps on 06-24-2008 09:47 AM
Re: System.Nul lPointerEx ception: Attempt to de-referen ce a null object
[ Edited ]
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-05-2010 01:20 PM - last edited on 09-05-2010 03:02 PM
Thanks gApps,
Its really a good catch, I was querying a null field in "QueryLocator start()", so it failed.
Covered this in a blog post too.

