My requirement is to get the list of territories present in an Account_Territory_Loader_vod__c object for a particular account and check that combination of account and territory whether it is present in TSF_vod__c or not. I am getting the following error : Attempt to de-reference a null object
Following is the code I have written :
global class AccountTerritoryCombination implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Account_vod__c,Id,Territory_vod__c FROM Account_Territory_Loader_vod__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account_Territory_Loader_vod__c> scope)
{
List<Id> Acc = new List<Id>();
List<String> Ter = new List<String>();
for(Account_Territory_Loader_vod__c ac: scope){
Acc.add(ac.account_vod__c);
if(ac.Territory_vod__c.length()>0){
Ter.add(ac.territory_vod__c);
}
}
List<TSF_vod__c> TSF = [select id,account_vod__c,territory_vod__c from TSF_vod__c where account_vod__c IN: Acc and territory_vod__c IN:Ter];
for(Account_Territory_Loader_vod__c a: scope){
integer i =0;
String S1;
if(a.territory_vod__c.length()>0){
S1 = a.territory_vod__c;
List<String> S2 = S1.split(';');
for(String S: S2){
for(TSF_vod__c t: TSF){
if(t.account_vod__c == a.account_vod__c && t.territory_vod__c == S){
system.debug('The combination is present');
}
else{
system.debug('The combination is not present');
}
}
}
}
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
}
}
Please tell me how to filter the account_territory_loader records where territory_vod__c is not null. Territory_vod__c is long text area so we can not filter using query. Please let me know if there are errors in this code.