You need to sign in to do that
Don't have an account?
Dean Blanch
HELP...I have created an apex trigger in sandbox to add the field "Number of Contacts" in to the account!
I have created an apex trigger in sandbox to add the field "Number of Contacts" in to the account in sandbox worked perfectly fine, however when deployed to production the field is empty.
trigger NumberOfContacts on Contact (after insert) {
set<id> setid = new set<id>();
list<account> listaccount = new list<account>();
for(contact con : trigger.new){
setid.add(con.accountid);
}
For(account acc : [select id,name,Number_of_Contacts__c, (select id from contacts)from account where id=:setid]) {
Account ac1 = new account();
ac1.id=acc.id;
ac1.Number_of_Contacts__c= acc.contacts.size();
listaccount.add(ac1);
}
update listaccount;
}
I tried this Trigger in my Developer Instance and then i deployed the same in my other instance using Packaging but i did not find any problem and the Trigger works fine in both the Orgs.
I don''t know why you are getting such problem in your Production Org. Can you please check if there is something else which is again updating the Record and add some Debug statements in you Trigger to check the ListDetails before the Actual Update Something like : system.debug('ListAccount-----'+listaccount); and then check the Debug log.
This way you might be able to get the reason behind the same.
Please let me know if you need some more assistance.
Thanks,
Jainam Contractor,
Saleforce Consultant,
Varasi LLC
www.varasi.com
Would I have to set up any of the following to bring through results...?
FieldsNew
Object
Validation RulesNew
Approvals
Cheers
Dean