• swapna muthiyalu
  • NEWBIE
  • 100 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 31
    Replies
For the line 2 the following error is thrown:

System.NullPointerException: Attempt to de-reference a null object

How to avoid this exception?

Please help.
Map<id,case> csmap = new Map<id,case>([select id,(select id,Type__c,Activities__r ) ,                  
                CaseNumber from case ];
       
list<Case> filterCas= new list<Case>();
 list<Activity__c> li = new list<Activity__c>(); 
for(case tempcase:csmap.values()){  
     
   for(Activity__c ac:tempcase.Activities__r){
       
       if (ac.Type__c == 'Info'){  
          filterCas.add(tempcase);
          }       
           
            
              system.debug('fitered Case'+ filterCas);
        
             Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
             String address = 'xxx@gmail.com';
             String subject = 'List of Records';             
        String[] toAddresses = new String[] {address};
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
     }
}





 

      
 
set<string>mEmpId = new set<string>();
map<string,id> MEmpIds = new map<string,id>(); 
list<Contact> con = [SELECT id,eid,AccountId, from Contact where (eid__c IN :mEmpId);
  for(Contact c : con)
        {
             if(mEmpId.contains(m.eid__c) 
            {
                MEmpIds.put(m.eid__c, c.Id);
            }
        }

how to use map of map for map<id,map<string,id>> MEmpIds = new map<string,id>();  and validate the put is from respective account id
i have this query, select id, accountid, seccon__r.accountid from contact..
now how to write the same query to check if accountid is equal to  seccon__r.accountid ?
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();

if (mEmpId .size() == 0 && hEmpId.size() > 0){

list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];

} else if(hEmpId.size() == 0 && mEmpId.size() > 0){

list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];

}else if (mEmpId.size() > 0 && hEmpId.size() > 0)


{list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];} ;

The requirement is i have account say Burlington textiles, i have many contacts and they have empid__c. similar way there are many accounts and related contacts with empid__c. but the empid__c may be same for many contacts. now i want to validate that the reportsto field in contact has the same contact which belongs to the same account,which is not validated in the above code. for example i have jack as contact who belongs to the account burligton, has Peter in the report to field, now i have to validate that peter also belongs to the burlington account.
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();
if (mEmpId .size() == 0){
list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];
} else if(hEmpId.size() == 0){
list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];
}else if (mEmpId.size() > 0 && hEmpId.size() > 0)
{list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];} ;
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();
 
list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ]

now i want to check if mEmpId and hEmpId are blank and if it is blank i have to run this query? how to check the set is empty?
 
Map<id,case> csmap = new Map<id,case>([select id,(select id,Type__c,Activities__r ) ,                  
                CaseNumber from case ];
       
list<Case> filterCas= new list<Case>();
 list<Activity__c> li = new list<Activity__c>(); 
for(case tempcase:csmap.values()){  
     
   for(Activity__c ac:tempcase.Activities__r){
       
       if (ac.Type__c == 'Info'){  
          filterCas.add(tempcase);
          }       
           
            
              system.debug('fitered Case'+ filterCas);
        
             Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
             String address = 'xxx@gmail.com';
             String subject = 'List of Records';             
        String[] toAddresses = new String[] {address};
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
     }
}





 

      
 
set<string>mEmpId = new set<string>();
map<string,id> MEmpIds = new map<string,id>(); 
list<Contact> con = [SELECT id,eid,AccountId, from Contact where (eid__c IN :mEmpId);
  for(Contact c : con)
        {
             if(mEmpId.contains(m.eid__c) 
            {
                MEmpIds.put(m.eid__c, c.Id);
            }
        }

how to use map of map for map<id,map<string,id>> MEmpIds = new map<string,id>();  and validate the put is from respective account id
i have this query, select id, accountid, seccon__r.accountid from contact..
now how to write the same query to check if accountid is equal to  seccon__r.accountid ?
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();

if (mEmpId .size() == 0 && hEmpId.size() > 0){

list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];

} else if(hEmpId.size() == 0 && mEmpId.size() > 0){

list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];

}else if (mEmpId.size() > 0 && hEmpId.size() > 0)


{list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];} ;

The requirement is i have account say Burlington textiles, i have many contacts and they have empid__c. similar way there are many accounts and related contacts with empid__c. but the empid__c may be same for many contacts. now i want to validate that the reportsto field in contact has the same contact which belongs to the same account,which is not validated in the above code. for example i have jack as contact who belongs to the account burligton, has Peter in the report to field, now i have to validate that peter also belongs to the burlington account.
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();
if (mEmpId .size() == 0){
list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];
} else if(hEmpId.size() == 0){
list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];
}else if (mEmpId.size() > 0 && hEmpId.size() > 0)
{list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];} ;
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();
 
list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ]

now i want to check if mEmpId and hEmpId are blank and if it is blank i have to run this query? how to check the set is empty?