You need to sign in to do that
Don't have an account?
craskulinecz
System.NullPointerException: Attempt to de-reference a null object
Ok, I'm getting the following error when using this Apex Trigger.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger copyMSGIdCases caused an unexpected exception, contact your administrator: copyMSGIdCases: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.copyMSGIdCases: line 21, column 56
Here is the code I am using:
Code:
So here is the funny thing, I only get this error if I am trying to create a new case as an regular user in SFDC. If I am logged in as the System Administrator, it all executes fine with no errors and does what I expect it to do.
Let me clarify, I am logged in as a System Admin User and then from there, go to Manage Users->Users, and choose the user I want to login as and then press the login button.
Has anyone run into this before?
Any suggestions?
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger copyMSGIdCases caused an unexpected exception, contact your administrator: copyMSGIdCases: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.copyMSGIdCases: line 21, column 56
Here is the code I am using:
Code:
// This trigger assigns a value to the MSG_ID__c custom field on cases before the new case // is saved to the database. trigger copyMSGIdCases on Case (before insert, before update) { // Determine the account Set<ID> accIds = new Set<ID>(); for (Case cas : Trigger.new) accIds.add(cas.accountid); // Query the Account to get the MSG_ID__c entry Map<Id, Account> entries = new Map<Id, Account>( [select MSG_ID__c, PAS_ID__c from Account where id in :accIds]); // Now set the Account_MSG_ID__c on the Contact to be the same as MSG_ID__c on the // related account // Now set the PAS_Account_ID__c on the Case to be the same as PAS_ID__c on the // related account for (Case cas : Trigger.new) cas.MSG_ID__c = entries.get(cas.AccountId).MSG_ID__c; for (Case cas : Trigger.new) cas.PAS_Account_ID__c = entries.get(cas.AccountId).PAS_ID__c; }Now, I'm sure this can be done in a different way, but I went this route because I wanted to learn more about Apex Triggers.
So here is the funny thing, I only get this error if I am trying to create a new case as an regular user in SFDC. If I am logged in as the System Administrator, it all executes fine with no errors and does what I expect it to do.
Let me clarify, I am logged in as a System Admin User and then from there, go to Manage Users->Users, and choose the user I want to login as and then press the login button.
Has anyone run into this before?
Any suggestions?
Message Edited by craskulinecz on 10-16-2007 10:36 PM
Message Edited by craskulinecz on 10-16-2007 10:38 PM
Code:
Chris
I came across this a lot of times. I guess one of the fields that you are assigning might be null (most probably PAS_ID__c). Pls try to eliminate nulls and see (and i know how hard it is) :smileyindifferent:
apex code::
<apex:page controller="resulttab">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!redirectToPage}" rerender="error"/>
</apex:pageBlockButtons>
<apex:inputField value="{!res.examid__c}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
class code::
public class resulttab
{
public result__c res {get; set;}
public String a {get; set;}
public List<result__c> getInfo()
{
a = res.examid__c;
return [SELECT name__c,college_name__c,branch__c,year__c,semester__c,clgno__c,total__c,status__c,percent__c,marks__c,examid__c FROM result__c WHERE examid__c=: res.examid__c ];
}
public PageReference redirectToPage()
{
return new PageReference('https://c.ap1.visual.force.com/apex/detailres');
}
}
error::
System.NullPointerException: Attempt to de-reference a null object
Class.resulttab.getInfo: line 8, column 1
Record present in result table then also null pointer exception occus...