I am trying to get the first 10 characters from "Patient_Name__c" field into the "Patient_Id_Help__c" field but when i run the batch class it is throwing the error as "Ending position out of bounds: 10 ". Please find my batch class below
global class DataLoad implements Database.Batchable<sObject>{
private String query;
private Integer recordcount = 0;
private boolean recurssion = true;
global Database.QueryLocator start(Database.BatchableContext BC)
{
query='Select id,Patient_Name__c from ZS_Reports__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<ZS_Reports__c> scope) {
recordCount=recordCount+scope.size();
List<ZS_Reports__c> zs=new List<ZS_Reports__c>();
for(ZS_Reports__c z:scope)
{
if(z.Patient_Name__c!=null)
{
z.Patient_Id_Help__c=z.Patient_Name__c.substring(0,10);
zs.add(z);
}
}
system.debug('Updated Records:'+zs.size());
if(zs.size()>0)
{
update zs;
}
}
global void finish(Database.BatchableContext bc)
{
}
}
Can somebody help me to solve this issue.