You need to sign in to do that
Don't have an account?
Hari nadh babu Eluru
Getting Multiple times output
Hi there !
In this batch Apex code, I updated Mr. infront of the name if student is Male and Mrs. infront of the name if student is Female but at in output Mr. or Mrs. is getting multiple times. Please give me the suggestions to remove the multiple times of getting Mr. and Mrs. and get only once.
The above image is multiple times getting Mr. and Mrs. in output
In this batch Apex code, I updated Mr. infront of the name if student is Male and Mrs. infront of the name if student is Female but at in output Mr. or Mrs. is getting multiple times. Please give me the suggestions to remove the multiple times of getting Mr. and Mrs. and get only once.
public class UpdateGender implements database.batchable<sobject> { public database.querylocator start(database.batchableContext abc){ string a = 'SELECT Student_Id__c, Name, Gender__c FROM Student__c'; return database.getquerylocator(a); } public void execute(database.batchableContext def, list<Student__c> x){ for(Student__c a : x){ if(a.Gender__c == 'Male'){ a.Name = 'Mr.'+a.Name; } else if(a.Gender__c == 'Female'){ a.Name = 'Mrs.'+a.Name; } } upsert x; } public void finish(database.batchableContext ghi){ system.debug('Finish::!'); } }
The above image is multiple times getting Mr. and Mrs. in output
Can you check if below code helps you.
If this solution helps you, please mark it as best answer.
Thanks,
All Answers
Are you running the batch multiple times.
Thanks,
Can you check if below code helps you.
If this solution helps you, please mark it as best answer.
Thanks,
@Sai Praveen, Thank you very Much !