You need to sign in to do that
Don't have an account?
❤Code
Trigger not working with data loader
Hi All,
I have an custom object where i have 3 record types. There is a trigger on this object which will calucate serial no for each record type and it will insert.
Ex -
Custom Object X__c.
Record Types = A, B , C
if i select record type A then one custom field will get inserted by A001.
if i select record type B then one custom field will get inserted by B001.
When i am uploading the data with data loader with batch size 20, for 20 records with record type A is having the same serial no A001.
Need help how to resolve this.
I have an custom object where i have 3 record types. There is a trigger on this object which will calucate serial no for each record type and it will insert.
Ex -
Custom Object X__c.
Record Types = A, B , C
if i select record type A then one custom field will get inserted by A001.
if i select record type B then one custom field will get inserted by B001.
When i am uploading the data with data loader with batch size 20, for 20 records with record type A is having the same serial no A001.
Need help how to resolve this.
--
Abhi
Bleow is the code snipet -
trigger ProjectOnUpdate on Project__c(before insert, before update, after update)
{
if(Trigger.isInsert){
Integer samplecount;
Integer Year = Date.Today().Year();
Integer Month = Date.Today().Month();
Project__c settings = Project__c.getInstance('SampleID');
ID bsg = settings.BSG__c;
ID it = settings.BS_IT__c;
ID opex = settings.Operation_Excellence__c;
ID cp = settings.Create_Project__c;
for(Project__c p : Trigger.new){
if(p.RecordTypeId == bsg) {
samplecount= [SELECT count() FROM Project__c WHERE RecordTypeId =: p.RecordTypeId];
p.Number__c = samplecount+1;
String s = String.valueOf(p.Number__c);
while (s.length() < 4) s = '0' + s;
p.Project_Serial_Number__c = 'BSG-'+Date.Today().Month()+'-'+Date.Today().Year()+'-S-'+s;
}
if(p.RecordTypeId == it) {
samplecount= [SELECT count() FROM Project__c WHERE RecordTypeId =: p.RecordTypeId];
p.Number__c = samplecount+1;
String s = String.valueOf(p.Number__c);
while (s.length() < 4) s = '0' + s;
p.Project_Serial_Number__c = 'BS IT-'+Date.Today().Month()+'-'+Date.Today().Year()+'-S-'+s;
}
if(p.RecordTypeId == opex) {
samplecount= [SELECT count() FROM Project__c WHERE RecordTypeId =: p.RecordTypeId];
p.Number__c = samplecount+1;
String s = String.valueOf(p.Number__c);
while (s.length() < 4) s = '0' + s;
p.Project_Serial_Number__c = 'OPEX-'+Date.Today().Month()+'-'+Date.Today().Year()+'-S-'+s;
}
if(p.RecordTypeId == cp) {
samplecount= [SELECT count() FROM Project__c WHERE RecordTypeId =: p.RecordTypeId];
p.Number__c = samplecount+1;
String s = String.valueOf(p.Number__c);
while (s.length() < 4) s = '0' + s;
p.Project_Serial_Number__c = p.Department_Name__c+'-'+Date.Today().Month()+'-'+Date.Today().Year()+'-S-'+s;
}
}
}