You need to sign in to do that
Don't have an account?
BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object
trigger SONo1 on Service__c (before insert) {
AutoNumber__c au=new AutoNumber__c(name='Service__c', In_Grantee__c=1001, Out_Of_Grantee__c=2001, etc__c=3001);
for(AutoNumber__c auto:[select id, name,In_Grantee__c,Out_Of_Grantee__c,etc__c from AutoNumber__c where name='Service__c'])
au=auto;
for(Service__c ser:Trigger.new)
{
if(ser.Status__c=='INGrantee')
{
ser.SONO__c=Integer.valueOf(au.In_Grantee__c++);
}
if(ser.Status__c=='OutofGrantee')
{
ser.SONO__c=Integer.valueOf(au.Out_Of_Grantee__c++);
}
if(ser.Status__c=='etc')
{
ser.SONO__c=Integer.valueOf(au.etc__c++);
}
}
upsert au;
}
Please tell me how to resolve this error..
On which line you are exactly getting the error ??
ser.SONO__c=Integer.valueOf(au.In_Grantee__c++);
ser.SONO__c=Integer.valueOf(au.Out_Of_Grantee__c++);
ser.SONO__c=Integer.valueOf(au.etc__c++);
In these lines i'm getting error according to choosing picklist value
Why have u added ++ after ur field names,you should be using __c with the field except the ++.
Change from
Out_Of_Grantee__c++
to
Out_Of_Grantee__c
I want to incrememt value of this field every time i insert a new record thats why i've used ++ in this.. This field value will increment if i don't use ++?
Try below :-
change from
ser.SONO__c=Integer.valueOf(au.In_Grantee__c++);
to
ser.SONO__c=Integer.valueOf(au.In_Grantee__c) + 1;
You are performing increment operation before converting to integer. Because your code "Integer.valueOf(au.In_Grantee__c++)" first increment the value then convert to integer.
So you have to perform the increment operation after converting to an integer.
Please refer to the below code.
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
Thanks and Regards
Suraj Tripathi.