You need to sign in to do that
Don't have an account?

Trigger to update custom setting
Hi All,
I have a trigger which will update Custom setting value. Whenever we are inserting records the count field on the custom setting will increment by that no of records, so if the current custom setting value is 1 and if I am inserting 10 records using dataloader, count will increment to 11 in custom setting. currently my code is working fine if I am trying to insert records manually one by one, but If I insert bulk load through dataloader, count is increment by 1 only. Please check my code and let me know what I am missing.
trigger newTrigger on TestApp__c (after insert) {
List<TestApp__c> newTest = new List<TestApp__c>();
Integer CountNumber;
//updateCount__c is custom setting
List<updateCount__c> mcs = new List<updateCount__c>();
mcs = updateCount__c.getall().values();
countNumber = Integer.valueof(mcs[0].count__c); //count__c is custom setting field where I am storing count of the records.
for(TestApp__c test:Trigger.new)
{
System.Debug('$$$$$$$$' +mcs[0].count__c);
mcs[0].count__c = countNumber+1;
}
System.Debug('$$$$$$$$' +mcs[0].count__c);
update mcs;
}
I have a trigger which will update Custom setting value. Whenever we are inserting records the count field on the custom setting will increment by that no of records, so if the current custom setting value is 1 and if I am inserting 10 records using dataloader, count will increment to 11 in custom setting. currently my code is working fine if I am trying to insert records manually one by one, but If I insert bulk load through dataloader, count is increment by 1 only. Please check my code and let me know what I am missing.
trigger newTrigger on TestApp__c (after insert) {
List<TestApp__c> newTest = new List<TestApp__c>();
Integer CountNumber;
//updateCount__c is custom setting
List<updateCount__c> mcs = new List<updateCount__c>();
mcs = updateCount__c.getall().values();
countNumber = Integer.valueof(mcs[0].count__c); //count__c is custom setting field where I am storing count of the records.
for(TestApp__c test:Trigger.new)
{
System.Debug('$$$$$$$$' +mcs[0].count__c);
mcs[0].count__c = countNumber+1;
}
System.Debug('$$$$$$$$' +mcs[0].count__c);
update mcs;
}
Instead, you can do one of two things: