You need to sign in to do that
Don't have an account?
Vignesh Ramshetty
The error with the screen short
HI
i have Customer_Policy_details__c object which is child to account which contines Expired, Active, getting expired records so, when ever the policy status changes to Getting expired or expired i want to update the count in account object below is the code please help where i went wrong
ERROR : I have taken screenshot
Public class forcount{
Public Static void makefunction (List<Customer_Policy_details__c> varnewCon,List<Customer_Policy_details__c> varold){
map<Id,Customer_Policy_details__c> varmaplist = new map<Id,Customer_Policy_details__c>();
if (varnewCon != null){
for(Customer_Policy_details__c varc : varnewCon){
if(varc.Account__c != null ){
varmaplist.put(varc.Account__c,varc);
}
}
}
if (varold != null){
for(Customer_Policy_details__c varcc : varold){
if(varcc.Account__c != null )
{
varmaplist.put(varcc.Account__c,varcc);
}
}
}
List<Account> varacclist = [SELECT id,Expired__c,Active_Policies__c,Acction_Required__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r)
FROM Account Where id in: varmaplist.keyset() AND Account.Customer_Policy_details__r.Policy_Status__c = 'Active'];
List<Account> varacclist1 = [SELECT id,Expired__c,Active_Policies__c,Acction_Required__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r)
FROM Account Where id in: varmaplist.keyset() AND Account.Customer_Policy_details__r.Policy_Status__c = 'Getting Expited'];
List<Account> varacclist2 = [SELECT id,Expired__c,Active_Policies__c,Acction_Required__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r)
FROM Account Where id in: varmaplist.keyset() AND Account.Customer_Policy_details__r.Policy_Status__c = 'Expired'];
if(varacclist.size() > 0) {
for(Account a : varacclist2 ){
for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{
system.debug('into this');
system.debug('size'+a.Customer_Policy_details__r.size());
if(csd.Policy_Status__c == 'Expired'){
a.Expired__c = a.Customer_Policy_details__r.size();
}
}
}
for(Account a : varacclist1 ){
for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{
if(csd.Policy_Status__c == 'Getting Expited'){
a.Acction_Required__c = a.Customer_Policy_details__r.size();
}
}
}
for(Account a : varacclist ){
for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{
if(csd.Policy_Status__c == 'Active'){
a.Active_Policies__c = a.Customer_Policy_details__r.size();
}
}
}
}
}
update varacclist;
update varacclist1;
update varacclist2;
}
}
}
i have Customer_Policy_details__c object which is child to account which contines Expired, Active, getting expired records so, when ever the policy status changes to Getting expired or expired i want to update the count in account object below is the code please help where i went wrong
ERROR : I have taken screenshot
Public class forcount{
Public Static void makefunction (List<Customer_Policy_details__c> varnewCon,List<Customer_Policy_details__c> varold){
map<Id,Customer_Policy_details__c> varmaplist = new map<Id,Customer_Policy_details__c>();
if (varnewCon != null){
for(Customer_Policy_details__c varc : varnewCon){
if(varc.Account__c != null ){
varmaplist.put(varc.Account__c,varc);
}
}
}
if (varold != null){
for(Customer_Policy_details__c varcc : varold){
if(varcc.Account__c != null )
{
varmaplist.put(varcc.Account__c,varcc);
}
}
}
List<Account> varacclist = [SELECT id,Expired__c,Active_Policies__c,Acction_Required__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r)
FROM Account Where id in: varmaplist.keyset() AND Account.Customer_Policy_details__r.Policy_Status__c = 'Active'];
List<Account> varacclist1 = [SELECT id,Expired__c,Active_Policies__c,Acction_Required__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r)
FROM Account Where id in: varmaplist.keyset() AND Account.Customer_Policy_details__r.Policy_Status__c = 'Getting Expited'];
List<Account> varacclist2 = [SELECT id,Expired__c,Active_Policies__c,Acction_Required__c,(SELECT id,Policy_Status__c FROM Customer_Policy_details__r)
FROM Account Where id in: varmaplist.keyset() AND Account.Customer_Policy_details__r.Policy_Status__c = 'Expired'];
if(varacclist.size() > 0) {
for(Account a : varacclist2 ){
for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{
system.debug('into this');
system.debug('size'+a.Customer_Policy_details__r.size());
if(csd.Policy_Status__c == 'Expired'){
a.Expired__c = a.Customer_Policy_details__r.size();
}
}
}
for(Account a : varacclist1 ){
for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{
if(csd.Policy_Status__c == 'Getting Expited'){
a.Acction_Required__c = a.Customer_Policy_details__r.size();
}
}
}
for(Account a : varacclist ){
for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{
if(csd.Policy_Status__c == 'Active'){
a.Active_Policies__c = a.Customer_Policy_details__r.size();
}
}
}
}
}
update varacclist;
update varacclist1;
update varacclist2;
}
}
}
try with below code.
If this helps, Please mark it as best answer.
Thanks!!