You need to sign in to do that
Don't have an account?
Vignesh Ramshetty
unable to update account when Cdp is deleated Can any one help please
hi,
unable to update account, Whenever the record is deleated the count is not reflecting in the account below is the code
Trigger For_counting_the_CPDrecords on Customer_Policy_details__c (after update,after delete){
if(trigger.isafter == true && trigger.isdelete == true){
updating_count_of_ploicies_in_Account.Method_for_calucating_when_deleated(trigger.oldMap);
}
public class updating_count_of_ploicies_in_Account {
Public static void Method_for_calucating_when_deleated (map<id,Customer_Policy_details__c> varoldmap){
map<id,Customer_Policy_details__c> varmaplist = new map<id,Customer_Policy_details__c>();
system.debug(varoldmap);
for(Customer_Policy_details__c varc : varoldmap.values()){
if(varc.Account__c != null){
varmaplist.put(varc.Account__c,varc);
system.debug(varmaplist);
}
}
List<Account> Addingrecords = [SELECT id,Expired__c,Active_Policies__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r where id in: varoldmap.keyset())
FROM Account WHERE id IN:varmaplist.keyset()];
system.debug(Addingrecords.size());
if(Addingrecords.size() > 0) {
for(Account vara : Addingrecords){
system.debug(Addingrecords);
for(Customer_Policy_details__c a : vara.Customer_Policy_details__r){
system.debug(vara.Customer_Policy_details__r);
if(a.Policy_Status__c == 'Active'){
system.debug(vara.Active_Policies__c);
vara.Active_Policies__c -=1;
system.debug(vara.Active_Policies__c);
}
if(a.Policy_Status__c == 'Expired'){
vara.Expired__c -=1;
}
}
}
update Addingrecords;
}
}
}
unable to update account, Whenever the record is deleated the count is not reflecting in the account below is the code
Trigger For_counting_the_CPDrecords on Customer_Policy_details__c (after update,after delete){
if(trigger.isafter == true && trigger.isdelete == true){
updating_count_of_ploicies_in_Account.Method_for_calucating_when_deleated(trigger.oldMap);
}
public class updating_count_of_ploicies_in_Account {
Public static void Method_for_calucating_when_deleated (map<id,Customer_Policy_details__c> varoldmap){
map<id,Customer_Policy_details__c> varmaplist = new map<id,Customer_Policy_details__c>();
system.debug(varoldmap);
for(Customer_Policy_details__c varc : varoldmap.values()){
if(varc.Account__c != null){
varmaplist.put(varc.Account__c,varc);
system.debug(varmaplist);
}
}
List<Account> Addingrecords = [SELECT id,Expired__c,Active_Policies__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r where id in: varoldmap.keyset())
FROM Account WHERE id IN:varmaplist.keyset()];
system.debug(Addingrecords.size());
if(Addingrecords.size() > 0) {
for(Account vara : Addingrecords){
system.debug(Addingrecords);
for(Customer_Policy_details__c a : vara.Customer_Policy_details__r){
system.debug(vara.Customer_Policy_details__r);
if(a.Policy_Status__c == 'Active'){
system.debug(vara.Active_Policies__c);
vara.Active_Policies__c -=1;
system.debug(vara.Active_Policies__c);
}
if(a.Policy_Status__c == 'Expired'){
vara.Expired__c -=1;
}
}
}
update Addingrecords;
}
}
}
Did you debug the code and checked at what point exactly the code is failing?
Thanks,
In the last for loop Below is the line for your reference from their is record is missing
for(Customer_Policy_details__c a : vara.Customer_Policy_details__r){
system.debug(vara.Customer_Policy_details__r);
Thank you,
Vignesh