You need to sign in to do that
Don't have an account?
Abhishek Singh 88
getting error Attempt to de-reference a null object
Hi Developers,
I have writtent code where i am checking that object__c have any duplicate value in text area field.I have written bellow code
for this one
Any help will be appriciated.
I have writtent code where i am checking that object__c have any duplicate value in text area field.I have written bellow code
if( ( email.subject.containsIgnoreCase('Ticket#') || email.subject.containsIgnoreCase('Ticket #') || email.subject.containsIgnoreCase('Incident#') || email.subject.containsIgnoreCase('Incident #') ) && email.subject.contains('[')){ ticketid = email.Subject.substring(email.Subject.indexOf('[')+1, email.Subject.indexOf(']')); }else if(email.subject.containsIgnoreCase('Ref:IN:')){ ticketid = email.subject.substring(email.Subject.indexOf('IN:')+3,email.Subject.indexOf(')')); } List<BMCServiceDesk__Incident__c> newinci=new List<BMCServiceDesk__Incident__c>(); system.debug('trying to insert ticket values'); for(BMCServiceDesk__Incident__c inci:[select id,BMCServiceDesk__EmailServiceAddress__c from BMCServiceDesk__Incident__c]) { if (inci.BMCServiceDesk__EmailServiceAddress__c.contains(ticketid)) { newinci.add(inci); system.debug('ticket id added to incident'); } }it showing Attempt to de-reference a null object error
for this one
for(BMCServiceDesk__Incident__c inci:[select id,BMCServiceDesk__EmailServiceAddress__c from BMCServiceDesk__Incident__c]) { if (inci.BMCServiceDesk__EmailServiceAddress__c.contains(ticketid)) { newinci.add(inci); system.debug('ticket id added to incident'); } }
Any help will be appriciated.
All Answers
Where have you declared it?
At first, in the block the possiblity is ticketid is null. Kindly initialize it to a blank value if not done already.
for(BMCServiceDesk__Incident__c inci:[select id,BMCServiceDesk__EmailServiceAddress__c from BMCServiceDesk__Incident__c])
{
if (inci.BMCServiceDesk__EmailServiceAddress__c != null && inci.BMCServiceDesk__EmailServiceAddress__c.contains(ticketid))
{
newinci.add(inci);
system.debug('ticket id added to incident');
}
}
it is showing error on line 10 column 1.
Thanks for your sugession.
I tried but still it giving same error.
If i remove if statement then it is working fine
String ticketId='';
this line is looping.,it not coming out from loop
This kind of FOR loops cannot go on forever.