You need to sign in to do that
Don't have an account?
Shivani Bankar
error: attempt to de-reference null object
hello,
I'm having attempt to de-reference null object error with following code
public class StringChecking{
public String name1{get; set;}
public List<contact> list2;
Contact contact1;
public Contact getContact(){
if(contact1!=null){
contact1=[select id,Name,Country__c from Contact where Name=:name1];
}
return contact1;
}
public pagereference ContactList(){
return null;
}
public List<Contact> getList(){
try{
if(contact1!=null && contact1.Country__c=='India'){
list2.add(contact1);
}
else if(contact1!=null && contact1.Country__c=='US'){
list2.add(contact1);
}
else{
list2.add(contact1);
}
}
catch(DmlException e)
{
System.debug('An unexpected error has occurred: ' + e.getMessage());
}
return list2;
}
public pagereference edit(){
pagereference pg=new Pagereference('https://ap5.salesforce.com/'+contact1.Id);
return pg;
}
}
please help me to solve this
I'm having attempt to de-reference null object error with following code
public class StringChecking{
public String name1{get; set;}
public List<contact> list2;
Contact contact1;
public Contact getContact(){
if(contact1!=null){
contact1=[select id,Name,Country__c from Contact where Name=:name1];
}
return contact1;
}
public pagereference ContactList(){
return null;
}
public List<Contact> getList(){
try{
if(contact1!=null && contact1.Country__c=='India'){
list2.add(contact1);
}
else if(contact1!=null && contact1.Country__c=='US'){
list2.add(contact1);
}
else{
list2.add(contact1);
}
}
catch(DmlException e)
{
System.debug('An unexpected error has occurred: ' + e.getMessage());
}
return list2;
}
public pagereference edit(){
pagereference pg=new Pagereference('https://ap5.salesforce.com/'+contact1.Id);
return pg;
}
}
please help me to solve this
All Answers