You need to sign in to do that
Don't have an account?
Vignesh Ramshetty
Error: Compile Error: Variable does not exist: Policy_Status__c at line 43 column 35
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
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.Policy_Status__c == 'Getting Expited' || varc.Policy_Status__c == 'Expired' ){
varmaplist.put(varc.Account__r.id,varc);
}
}
}
if (varold != null){
for(Customer_Policy_details__c varcc : varold){
if(varcc.Policy_Status__c == 'Getting Expited' || varcc.Policy_Status__c == 'Expired' || varcc.Policy_Status__c == 'Active')
{
varmaplist.put(varcc.Account__r.id,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()];
if(varacclist.size() > 0) {
for(Account a : varacclist ){
if(a.Policy_Status__c == 'Expired'){
a.Expired__c = a.Customer_Policy_details__r.size();
}
if(a.Policy_Status__c == 'Getting Expited'){
a.Acction_Required__c = a.Customer_Policy_details__r.size();
}
}
update varacclist;
}
}
}
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
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.Policy_Status__c == 'Getting Expited' || varc.Policy_Status__c == 'Expired' ){
varmaplist.put(varc.Account__r.id,varc);
}
}
}
if (varold != null){
for(Customer_Policy_details__c varcc : varold){
if(varcc.Policy_Status__c == 'Getting Expited' || varcc.Policy_Status__c == 'Expired' || varcc.Policy_Status__c == 'Active')
{
varmaplist.put(varcc.Account__r.id,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()];
if(varacclist.size() > 0) {
for(Account a : varacclist ){
if(a.Policy_Status__c == 'Expired'){
a.Expired__c = a.Customer_Policy_details__r.size();
}
if(a.Policy_Status__c == 'Getting Expited'){
a.Acction_Required__c = a.Customer_Policy_details__r.size();
}
}
update varacclist;
}
}
}
Can you confirm if you have Policy_Status__c field on Account object?
Thanks,
You need to iterate through child records to check the condition on child object like below,
Check the below link (https://www.sfdcpoint.com/salesforce/relationship-query-apex-salesforce/) for more details on it.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Did you get chance to check if the code is going into If statement by using debug?
Thanks,
There were some minor issues in the code. I have updated it. can you check now.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,