function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nirmal ChristopherNirmal Christopher 

Need help with string methods

Hi i am trying to build a trigger when mass import is done using a data loader the trigger should save the file in specific formats. For Example IF Job__c is the master object and jobApplicant__c is the child object when doing bulk imports the files should get saved in the following format
JA-0001.0002
JA-0001.0003
JA-0001.0004
 where '0001' comes from the master record name and 0002 is the indvidual child records related to the master.
below is the sample code please help me with the working code
trigger updateAppplicantName on Job_Applicants__c (before insert, before update) {
set<id> vacSet = new set<id>();
for(Job_Applicants__c ja:trigger.new){
vacSet.add(ja.Job_Name__c);
}           
  System.debug('***vacSet***'+vacSet); 
  list<Job_Applicants__c >japp=[select id,name,Job_Name__r.name from Job_Applicants__c where Job_Name__c IN:vacSet order by createddate desc limit 1 ];
String vName='' ;
  string jobname;
  integer num;
  jobname=japp[0].Job_Name__r.name ;
  String jobApplicant=japp[0].name;
  String jobApplicant1=jobApplicant.substring(8,12);
  num=integer.valueof(jobApplicant1);
string AppName=japp[0].name;
String Jobname1=jobname.substring(3,7);
  for(Job_Applicants__c jaa:trigger.new){
  jaa.name='JA-'+Jobname1+num+1;
 
    }
}

Thanks in Advance.
Abhi__SFDCAbhi__SFDC
try below code

trigger updateAppplicantName on Job_Applicants__c (before insert, before update) {
Set<ID> ids = Trigger.new.keySet();
  for(Job_Applicants__c  japp : [select id,name,Job_Name__r.name from Job_Applicants__c where Job_Name__c IN:ids order by createddate desc ]) {
 
japp.name = 'JA-'+japp.Job_Name__r.name.substring(3,7)+(integer.valueof(japp.name.substring(8,12) + 1)); 
  }
}

Let me know if you get any issues