• Vignesh Ramshetty
  • NEWBIE
  • 60 Points
  • Member since 2022
  • Salesforce developer
  • intelogik

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 25
    Questions
  • 24
    Replies
<aura:component controller="Approval_Process_Details" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    
    <aura:attribute name="records" type="Object[]" />
     <aura:attribute name="columns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <lightning:card title="Approval Card" iconName="standard:approval">
    <lightning:datatable
        keyField="Id"
        data="{!v.records}"
        columns="{!v.columns}"
        hideCheckboxColumn="true"
       onrowselection="{!c.handleRowSelection}"
      
       showRowNumberColumn="true"
    />
          </lightning:card>
</aura:component>

Controller.js:
({
     doInit: function(component, event, helper) {
         
       
        helper.fetchData(component, event, helper);
       
    },
     handleRowSelection: function(component, event, helper) {
       alert('Hi')
    }

  
})

helper:
({
    fetchData: function(component, event, helper) {
        
        var action = component.get("c.Approval_Process_Details_Method");
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            
            if (state === "SUCCESS") {
                var records = response.getReturnValue();
                var tempRecs = [];
              
                component.set("v.records", records);
                 component.set("v.columns", [
                     { label: 'Opportunity Name', fieldName: 'Opp_Id', type: 'url',
                      typeAttributes: { label: { fieldName: 'Opp_Name' }, target: '_self ', onclick: 'navigateToRecordPage'}
              },
                    
                     { label: "Comment", fieldName: "Claim_Comment", type: "text" },
                    { label: "Close Date", fieldName: "Opp_CLose_Won", type: "text" },
                    { label: "Date Of Approvel Applied", fieldName: "User_Applied_Date", type: "text" },
                    { label: "Owner Name", fieldName: "Opp_Owner_Name", type: "text" },
                    
                    { label: "Name Of User Who Submitted", fieldName: "User_Who_Submitted", type: "text" },
                    
                    {
                    type: "button",
                    typeAttributes: {
                    label: "Approve",
                    name: "approve",
                    title: "Approve",
                    value: "Id"
                   
                    },
                         onclick: component.getReference("c.handleApprove")
                    },
                    {
                    type: "button",
                    typeAttributes: {
                    label: "Reject",
                    name: "reject",
                    title: "Reject",
                    value: "Id"
                    }
                    }
                ]);
                
            }
        });
        $A.enqueueAction(action);
    },
   
    
})
 List<ProcessInstance> listview = [SELECT Id, TargetObject.Name,CreatedDate,TargetObjectId,(SELECT Id, ActorId, ProcessInstanceId FROM Workitems WHERE Actor.Name = 'Mala Srinivas'),(SELECT Id, StepStatus, Comments FROM StepsAndWorkitems),SubmittedBy.Name,SubmittedById,Status, LastModifiedDate FROM ProcessInstance where Status='Pending'];


for(ProcessInstance:listview){
             for (ProcessInstanceHistory history : pri.StepsAndWorkitem) {
                 //Need to get comments out of the queary
             }

}

//queary is working good but if i loop unable to get the data of child object

Getting error = Variable does not exist: StepsAndWorkitem;
How to logout a user from test class :

trigger Logoutinfo on LogoutEventStream (after insert) {
    
    
    
    if(trigger.isafter == true && trigger.isinsert == true){
        
        Logoutinfoclass.Logoutinfoclassmethod(trigger.new);
        
    }

    
}



public class Logoutinfoclass {
    
    public static void Logoutinfoclassmethod(list<LogoutEventStream> listlogout){
        
        
        
        List <User> userList= new List <User>();

for( LogoutEventStream les:listlogout)

{

  for(User userInfo: [Select ID,Last_Logout__c From User where ID =: les.UserID] ) 

  {  

  userInfo.Last_Logout__c=System.now();

  userList.add(userInfo);  

  } 

}
    update userList;
  }

}
Whenever any record is created in any object we want to run a timer if it reach 15 min then we want to perform business logic , Can any one help of creating this by apex class ?

 
openGreetings.cmp :
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
    <aura:attribute name="pageReference" type="Object"/>
    <lightning:workspaceAPI aura:id="workspace"/>
    <lightning:button label="Open Greeting in Subtab" onclick="{!c.openSubtab}"/>
    <lightning:input label="Name" name="myname"/>
</aura:component>

openGreetingsController.js :
({
    openSubtab: function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getEnclosingTabId().then(function(enclosingTabId) {
            workspaceAPI.openSubtab({
                parentTabId: enclosingTabId,
                pageReference: {
                    "type": "standard__component",
                    "attributes": {
                        "componentName": "c__greetings"
                    },
                    "state": {
                        "uid": "1",
                        "c__name": component.get("v.myName")
                    }
                }
            }).then(function(subtabId) {
                console.log("The new subtab ID is:" + subtabId);
            }).catch(function(error) {
                console.log("error");
            });
        });
    }
})


 greetings.cmp : 

<aura:component implements="lightning:isUrlAddressable">
    <aura:attribute name="name" type="String" description="The person that will be greeted" />
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <aura:handler name="change" value="{!v.pageReference}" action="{!c.handlePageChange}" />
    <h1>Greeting Page</h1>
    <div>Hello, {!v.name}</div>
</aura:component>

greetingsController.js : 

({
    init: function(cmp, evt, hlp) {
        var myPageRef = cmp.get("v.pageReference");
        var name = myPageRef && myPageRef.state ? myPageRef.state.c__name : "World";
        cmp.set("v.name", name);
    },
    handlePageChange: function(cmp, evt, hlp) {
        var myPageRef = cmp.get("v.pageReference");
        var name = myPageRef && myPageRef.state ? myPageRef.state.c__name : "World";
        cmp.set("v.name", name);
    }
})

Getting error is  = Error: Invalid or missing parentTabId `false`
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; 
        }
   }
}
hi,
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; 
        }
   }
}
HI
 Below is the code which iam calling whenever  the record is inserted , updated, deleated , undeleated  i able to get the count of releated to that account But i want the filter the count based on policy status and need to update that size can anyone help on this please. 



Trigger forcounttherecords on Customer_Policy_details__c (After insert, After Update , After delete ,After undelete){


    if(trigger.isafter==true &&(trigger.isinsert== true || trigger.isupdate == true || trigger.isdelete == true || trigger.isundelete == true)){
      
                forcountingCDPrecords.Methodforcounting(trigger.new,trigger.old);
    }
 }




Public class forcountingCDPrecords{

Public Static void Methodforcounting (List<Customer_Policy_details__c> varnewCon,List<Customer_Policy_details__c> varold){


                         map<Id,Customer_Policy_details__c> varActivelist = new map<Id,Customer_Policy_details__c>();
                          map<Id,Customer_Policy_details__c> varGettingexpitedlist = new map<Id,Customer_Policy_details__c>();
                         map<Id,Customer_Policy_details__c> varexpiredlist = new map<Id,Customer_Policy_details__c>();
                         
     if (varnewCon != null){

         for(Customer_Policy_details__c varc : varnewCon){

                  if(varc.Account__c != null && varc.Policy_Status__c == 'Active'){
                    
                  varActivelist.put(varc.Account__c,varc);
                  }
                  
                  else if (varc.Account__c != null && varc.Policy_Status__c == 'Getting Expited'){
                    
                     varGettingexpitedlist.put(varc.Account__c,varc);
                  
                  }
                  else if (varc.Account__c != null && varc.Policy_Status__c == 'Expired'){
                    
                     varexpiredlist.put(varc.Account__c,varc);

           }

       }

    }

  if (varold != null){

         for(Customer_Policy_details__c varcc : varold){

  if(varcc.Account__c != null && varcc.Policy_Status__c == 'Active'){
                    
                  varActivelist.put(varcc.Account__c,varcc);
                  }
                  
      else if(varcc.Account__c != null && varcc.Policy_Status__c == 'Getting Expited'){
                  varGettingexpitedlist.put(varcc.Account__c,varcc);
       
       }   
       else if (varcc.Account__c != null && varcc.Policy_Status__c == 'Expired'){
                     varexpiredlist.put(varcc.Account__c,varcc);
       
        }         
           

       }

    }

List<Account> GettingActivelist= [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: varActivelist.keyset()];
 
 
 if(GettingActivelist.size() > 0) {
                   
                        for(Account a : GettingActivelist){
  
                           a.Active_Policies__c = a.Customer_Policy_details__r.size();
                           
                           
                           }
             update GettingActivelist;           
 

      }
      
 List<Account> GettingActionrequiredlist= [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: varGettingexpitedlist.keyset()];
 
 
 if(GettingActivelist.size() > 0) {
                   
                        for(Account a : GettingActionrequiredlist){
  
                           a.Acction_Required__c = a.Customer_Policy_details__r.size();
                           
                           
                           }
             update GettingActionrequiredlist;           
 

      }     
      
 List<Account> GettingExpiredlist= [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: varexpiredlist.keyset()];
 
 
 if(GettingExpiredlist.size() > 0) {
                   
                        for(Account a : GettingExpiredlist){
  
                           a.Expired__c = a.Customer_Policy_details__r.size();
                           
                           
                           }
             update GettingExpiredlist;           
 

      }      
      
      

  }

}
HI
 Below is the code which iam calling whenever  the record is inserted , updated, deleated , undeleated  i able to get the count of releated to that account But i want the filter the count based on policy status and need to update that size can anyone help on this please. 

Public class forcountingCDPrecords{

Public Static void Methodforcounting (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()];
 
 
 if(varacclist.size() > 0) {
                   
                        for(Account a : varacclist  ){
                            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();
          }

                 else if(csd.Policy_Status__c == 'Getting Expited'){

                           a.Acction_Required__c = a.Customer_Policy_details__r.size();

           }
              else   if(csd.Policy_Status__c == 'Active'){

                           a.Active_Policies__c = a.Customer_Policy_details__r.size();

           }
        }
}

       update varacclist; 

      }

  }

}
 
Hi able to save the class but changes are not reflectiong in the account


trigger  Checking on Customer_Policy_details__c (Before Insert , Before Update , After Insert , After update) {

if(trigger.isbefore == true &&(trigger.isinsert == true || trigger.isupdate == true)) {

               CPDclass.beforemethod(trigger.new);

    }

if(trigger.isafter == true &&(trigger.isinsert == true || trigger.isupdate == true)) {

               CPDclass.Aftermethod(trigger.new);

    }



Public Class CPDclass{


Public Static void beforemethod(List<Customer_Policy_details__c> CPDlist){

                for(Customer_Policy_details__c varc : CPDlist){


                        varc.Text_for_before__c =  'before exec';


             
       }

  }

    Public Static void Aftermethod(List<Customer_Policy_details__c> CPDlist1){


                       set<string> varset = new set<string>();

              for(Customer_Policy_details__c varc : CPDlist1){


                                varset.add(varc.Account__r.id);

  }
        
        
 system.debug(varset.size());
        
        
      List<Account> varacc = [SELECT id,Name,(SELECT id FROM Customer_Policy_details__r) From Account Where id in: varset];
      
      

        if(varacc.size() > 0) {
               for(Account a :varacc){

                      a.Name = 'after exec';
                      
                    
     }
            update varacc;
        }

      

   }
}
I have Customer_Policy_details__c  object which is child to Account object  it has masterdetail relationsip so, their is 
Policy_Status__c filed so it is picklist it has three values (Active, Expired,
Getting expired) and i have three fields in Account object  i.e,  Expired__c,  Acction_Required__C , Active_policies__c 
so, if status is changed to 
Getting expired or expired i have to update  i have to count the numbervof records which are in Expired, Getting expired , expired records count on account object  . with below code i am getting total number of records i need how many expired , how many are getting expired , how many are active  based on that number i should update 
 releated account record fields. 




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()];

    
    if(varacclist.size() > 0) {
                   
                        for(Account a : varacclist  ){
                            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();
          }

                 else if(csd.Policy_Status__c == 'Getting Expited'){

                           a.Acction_Required__c = a.Customer_Policy_details__r.size();

           }
              else   if(csd.Policy_Status__c == 'Active'){

                           a.Active_Policies__c = a.Customer_Policy_details__r.size();

           }
        }
}

       update varacclist; 

      }

  }

}
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 screenshotUser-added image



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;
      }

  }

}
 
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 or deleated i want to update the count in account object below is the code able to save the class but count is not updating in Account object can anyone help.



trigger forcounting on Customer_Policy_details__c (after update,after delete) {



forcount.makefunction(trigger.new,trigger.old);



}


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__r != null ){
                    
                  varmaplist.put(varc.Account__r.id,varc);

           }

       }

    }

  if (varold != null){

         for(Customer_Policy_details__c varcc : varold){

                       if(varcc.Account__r != null )
{
                    
                  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  ){
                            for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{

                             if(csd.Policy_Status__c == 'Expired'){

                           a.Expired__c = a.Customer_Policy_details__r.size();
          }

                 else if(csd.Policy_Status__c == 'Getting Expited'){

                           a.Acction_Required__c = a.Customer_Policy_details__r.size();

           }
              else   if(csd.Policy_Status__c == 'Active'){

                           a.Active_Policies__c = a.Customer_Policy_details__r.size();

           }
        }
}

       update varacclist; 

      }

  }

}
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 or deleated i want to update the count in account object below is the code able to save the class but count is not updating in Account object can anyone help.


trigger forcounting on Customer_Policy_details__c (after update,after delete) {



forcount.makefunction(trigger.new,trigger.old);



}


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__r != null ){
                    
                  varmaplist.put(varc.Account__r.id,varc);

           }

       }

    }

  if (varold != null){

         for(Customer_Policy_details__c varcc : varold){

                       if(varcc.Account__r != null )
{
                    
                  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  ){
                            for(Customer_Policy_details__c csd:a.Customer_Policy_details__r)
{

                             if(csd.Policy_Status__c == 'Expired'){

                           a.Expired__c = a.Customer_Policy_details__r.size();
          }

                 else if(csd.Policy_Status__c == 'Getting Expited'){

                           a.Acction_Required__c = a.Customer_Policy_details__r.size();

           }
              else   if(csd.Policy_Status__c == 'Active'){

                           a.Active_Policies__c = a.Customer_Policy_details__r.size();

           }
        }
}

       update varacclist; 

      }

  }

}
 
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; 

      }

  }

}
APEX CLASS:

Public class Sample321{

Public List<Wapperclass> ListWrapper {set;get;}



public Sample321(){



List<Property__c> listtec = [SELECT Name FROM Property__c LIMIT 10];
List<Account> listacc = [SELECT Name FROM Account LIMIT 5];

 

   if(listacc.size() > 0){

      ListWrapper = new List<Wapperclass>();

        for(Account a : listacc){
          ListWrapper.add(new Wapperclass(a));
  }


}
     if(listtec.size() > 0){

      ListWrapper = new List<Wapperclass>();

        for(Property__c T : listtec ){
          ListWrapper.add(new Wapperclass(T));
  }


}

}

public class Wapperclass {
Public Boolean checkbool {get;set;}
Public Account acct {get;set;}
Public Property__c tecc {get;set;}

Public Wapperclass (Property__c tecc){
        this.tecc  = tecc;

}
Public Wapperclass (Account  acct){
        this.acct = acct;
        }

}

}


VISUALFORCE PAGE : 
<apex:page Controller="Sample321">
<apex:form >
<apex:pageBlock title="List Data">
<apex:pageMessages />
<apex:pageBlockSection >
<apex:pageBlockTable value="{!ListWrapper}" var="me" >
<apex:column > <apex:inputCheckbox value="{!me.checkBool}"/> </apex:column>
<apex:column value="{!me.acct.Name}"/>
<apex:column value="{!me.tecc.Name}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

User-added image
Apex Class:
Public with sharing class AccountHealper{

@AuraEnabled (cacheable=true) 

  public static List<Account> getfunction() {
  list<Account> varacclist = new list<Account> ();
  
  varacclist = [SELECT id,  Name FROM Account];
  
  Return varacclist;
  }
  }



<aura:component controller = "AccountHealper">


<aura:attribute name = "contactlist" type = "object"/>



<lightning:button label = "click here" onclick = "{!c.handeler}"/>


    <aura:iteration items = "{!v.contactlist}" var = "varcon"/>
    
   <p>  {!varcon}</p>


</aura:component>



({

   handeler : function(event,component,helper){


       var action = component.get("c.getfunction");

       action.setCallback(this,function(responce){

           var state = response.getState();

      if(state == "SUCCESS"){

           var result = response.getReturnValue();


         component.set("v.contactlist",result);

  }





});
    $A.enqueueAction(action);
}
})

User-added image
This page has an error. You might just need to refresh it. Action failed: c:ittortercomponent$controller$handeler [component.get is not a function] Failing descriptor: {c:ittortercomponent$controller$handeler}
If I insert contact record the related account record employees number should be updated below is the code able to save but  account record is not updating in account record.


public class contactclass2 {

public static void makefunction(List<Contact> varcon){
 
set<string> varset = new set<string>();


for(contact con :varcon ){

         if(con.Accountid != null){

              varset.add(con.Accountid);
      }

    }
if(varset.size() > 0){
list<Account> varacc = new list<Account>();


varacc = [SELECT id,Name,Fax,NumberOfEmployees,(Select id From contacts) FROM ACCOUNT WHERE id in: varacc];

if(varacc.size() > 0 ){

for(Account a : varacc){

      
             a.NumberOfEmployees  = a.contacts.size();

            varacc.add(a);
   }

update varacc;

 }
 }
 }

}


trigger Uff on Contact (after insert) {

   contactclass2.makefunction(trigger.new);

}
Whenever the record inserted need to insert another record with same data


trigger opprunitybeforeandafter on Opportunity (Before insert, after insert){

if(trigger.isbefore == true && trigger.isinsert == true){

         oppurinityamountclass.makefunction(trigger.new);
}
if(trigger.isafter == true && trigger.isinsert == true){

           oppurinityamountclass.makefunction2(trigger.new,trigger.oldMap);
}
}User-added image









Public class oppurinityamountclass{
    
    Public static void makefunction(list<Opportunity> varocc){
        
        for(Opportunity varo : varocc){
            if (varo.Amount >= 50000){
                varo.Amount = varo.Amount/2;
            }
        }
    }
    
    
    Public static void makefunction2(list<Opportunity> varocd,map<id,Opportunity> varold){
        
        
        List<Opportunity> varins = new List<Opportunity>();
        
        for (Opportunity opp : varocd ){
            
            
            
         
            
            opp.Name = varold.get(opp.id).Name;
            opp.CloseDate = varold.get(opp.id).CloseDate;
            opp.StageName = varold.get(opp.id).StageName;
            
            varins.add(opp);
        }
        insert varins;
    }
}
 List<ProcessInstance> listview = [SELECT Id, TargetObject.Name,CreatedDate,TargetObjectId,(SELECT Id, ActorId, ProcessInstanceId FROM Workitems WHERE Actor.Name = 'Mala Srinivas'),(SELECT Id, StepStatus, Comments FROM StepsAndWorkitems),SubmittedBy.Name,SubmittedById,Status, LastModifiedDate FROM ProcessInstance where Status='Pending'];


for(ProcessInstance:listview){
             for (ProcessInstanceHistory history : pri.StepsAndWorkitem) {
                 //Need to get comments out of the queary
             }

}

//queary is working good but if i loop unable to get the data of child object

Getting error = Variable does not exist: StepsAndWorkitem;
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; 
        }
   }
}
HI
 Below is the code which iam calling whenever  the record is inserted , updated, deleated , undeleated  i able to get the count of releated to that account But i want the filter the count based on policy status and need to update that size can anyone help on this please. 



Trigger forcounttherecords on Customer_Policy_details__c (After insert, After Update , After delete ,After undelete){


    if(trigger.isafter==true &&(trigger.isinsert== true || trigger.isupdate == true || trigger.isdelete == true || trigger.isundelete == true)){
      
                forcountingCDPrecords.Methodforcounting(trigger.new,trigger.old);
    }
 }




Public class forcountingCDPrecords{

Public Static void Methodforcounting (List<Customer_Policy_details__c> varnewCon,List<Customer_Policy_details__c> varold){


                         map<Id,Customer_Policy_details__c> varActivelist = new map<Id,Customer_Policy_details__c>();
                          map<Id,Customer_Policy_details__c> varGettingexpitedlist = new map<Id,Customer_Policy_details__c>();
                         map<Id,Customer_Policy_details__c> varexpiredlist = new map<Id,Customer_Policy_details__c>();
                         
     if (varnewCon != null){

         for(Customer_Policy_details__c varc : varnewCon){

                  if(varc.Account__c != null && varc.Policy_Status__c == 'Active'){
                    
                  varActivelist.put(varc.Account__c,varc);
                  }
                  
                  else if (varc.Account__c != null && varc.Policy_Status__c == 'Getting Expited'){
                    
                     varGettingexpitedlist.put(varc.Account__c,varc);
                  
                  }
                  else if (varc.Account__c != null && varc.Policy_Status__c == 'Expired'){
                    
                     varexpiredlist.put(varc.Account__c,varc);

           }

       }

    }

  if (varold != null){

         for(Customer_Policy_details__c varcc : varold){

  if(varcc.Account__c != null && varcc.Policy_Status__c == 'Active'){
                    
                  varActivelist.put(varcc.Account__c,varcc);
                  }
                  
      else if(varcc.Account__c != null && varcc.Policy_Status__c == 'Getting Expited'){
                  varGettingexpitedlist.put(varcc.Account__c,varcc);
       
       }   
       else if (varcc.Account__c != null && varcc.Policy_Status__c == 'Expired'){
                     varexpiredlist.put(varcc.Account__c,varcc);
       
        }         
           

       }

    }

List<Account> GettingActivelist= [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: varActivelist.keyset()];
 
 
 if(GettingActivelist.size() > 0) {
                   
                        for(Account a : GettingActivelist){
  
                           a.Active_Policies__c = a.Customer_Policy_details__r.size();
                           
                           
                           }
             update GettingActivelist;           
 

      }
      
 List<Account> GettingActionrequiredlist= [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: varGettingexpitedlist.keyset()];
 
 
 if(GettingActivelist.size() > 0) {
                   
                        for(Account a : GettingActionrequiredlist){
  
                           a.Acction_Required__c = a.Customer_Policy_details__r.size();
                           
                           
                           }
             update GettingActionrequiredlist;           
 

      }     
      
 List<Account> GettingExpiredlist= [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: varexpiredlist.keyset()];
 
 
 if(GettingExpiredlist.size() > 0) {
                   
                        for(Account a : GettingExpiredlist){
  
                           a.Expired__c = a.Customer_Policy_details__r.size();
                           
                           
                           }
             update GettingExpiredlist;           
 

      }      
      
      

  }

}
Hi able to save the class but changes are not reflectiong in the account


trigger  Checking on Customer_Policy_details__c (Before Insert , Before Update , After Insert , After update) {

if(trigger.isbefore == true &&(trigger.isinsert == true || trigger.isupdate == true)) {

               CPDclass.beforemethod(trigger.new);

    }

if(trigger.isafter == true &&(trigger.isinsert == true || trigger.isupdate == true)) {

               CPDclass.Aftermethod(trigger.new);

    }



Public Class CPDclass{


Public Static void beforemethod(List<Customer_Policy_details__c> CPDlist){

                for(Customer_Policy_details__c varc : CPDlist){


                        varc.Text_for_before__c =  'before exec';


             
       }

  }

    Public Static void Aftermethod(List<Customer_Policy_details__c> CPDlist1){


                       set<string> varset = new set<string>();

              for(Customer_Policy_details__c varc : CPDlist1){


                                varset.add(varc.Account__r.id);

  }
        
        
 system.debug(varset.size());
        
        
      List<Account> varacc = [SELECT id,Name,(SELECT id FROM Customer_Policy_details__r) From Account Where id in: varset];
      
      

        if(varacc.size() > 0) {
               for(Account a :varacc){

                      a.Name = 'after exec';
                      
                    
     }
            update varacc;
        }

      

   }
}
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; 

      }

  }

}
Apex Class:
Public with sharing class AccountHealper{

@AuraEnabled (cacheable=true) 

  public static List<Account> getfunction() {
  list<Account> varacclist = new list<Account> ();
  
  varacclist = [SELECT id,  Name FROM Account];
  
  Return varacclist;
  }
  }



<aura:component controller = "AccountHealper">


<aura:attribute name = "contactlist" type = "object"/>



<lightning:button label = "click here" onclick = "{!c.handeler}"/>


    <aura:iteration items = "{!v.contactlist}" var = "varcon"/>
    
   <p>  {!varcon}</p>


</aura:component>



({

   handeler : function(event,component,helper){


       var action = component.get("c.getfunction");

       action.setCallback(this,function(responce){

           var state = response.getState();

      if(state == "SUCCESS"){

           var result = response.getReturnValue();


         component.set("v.contactlist",result);

  }





});
    $A.enqueueAction(action);
}
})

User-added image
This page has an error. You might just need to refresh it. Action failed: c:ittortercomponent$controller$handeler [component.get is not a function] Failing descriptor: {c:ittortercomponent$controller$handeler}
Whenever the record inserted need to insert another record with same data


trigger opprunitybeforeandafter on Opportunity (Before insert, after insert){

if(trigger.isbefore == true && trigger.isinsert == true){

         oppurinityamountclass.makefunction(trigger.new);
}
if(trigger.isafter == true && trigger.isinsert == true){

           oppurinityamountclass.makefunction2(trigger.new,trigger.oldMap);
}
}User-added image









Public class oppurinityamountclass{
    
    Public static void makefunction(list<Opportunity> varocc){
        
        for(Opportunity varo : varocc){
            if (varo.Amount >= 50000){
                varo.Amount = varo.Amount/2;
            }
        }
    }
    
    
    Public static void makefunction2(list<Opportunity> varocd,map<id,Opportunity> varold){
        
        
        List<Opportunity> varins = new List<Opportunity>();
        
        for (Opportunity opp : varocd ){
            
            
            
         
            
            opp.Name = varold.get(opp.id).Name;
            opp.CloseDate = varold.get(opp.id).CloseDate;
            opp.StageName = varold.get(opp.id).StageName;
            
            varins.add(opp);
        }
        insert varins;
    }
}
If one record is inserted i want to insert another record with same information
Trigger : 
trigger opprunitybeforeandafter on Opportunity (Before insert, after insert){

if(trigger.isbefore == true && trigger.isinsert == true){

         oppurinityamountclass.makefunction(trigger.new);
}
if(trigger.isafter == true && trigger.isinsert == true){

           oppurinityamountclass.makefunction2(trigger.new,trigger.oldMap);
}
}User-added image




Public class oppurinityamountclass{

     Public static void makefunction(list<Opportunity> varocc){

         for(Opportunity varo : varocc){
           if (varo.Amount >= 50000){
          varo.Amount = varo.Amount/2;
      }
    }
}

    
    Public static void makefunction2(list<Opportunity> varocd,map<id,Opportunity> varold){

     
          List<Opportunity> varins = new List<Opportunity>();

      for (Opportunity opp : varocd ){

  

          opp.Amount = varold.get(opp.id).Amount;

          opp.Name = varold.get(opp.id).Name;
          opp.CloseDate = varold.get(opp.id).CloseDate;
          opp.StageName = varold.get(opp.id).StageName;
         
           varins.add(opp);




}
insert varins;
}
Contact con  = new  Contact();

con.Firstname = 'Vignesh';
con.Lastname = 'Ramshetty';
con.Phone = '9666266129';

insert con;
Public class accountrecord {

Public static void making(List<Account> varacc){

           Map<Id,Account> varmap = new  Map<Id,Account>();

          List <Contact> listcontact = new List <Contact>(); 
        
           
 
          for(Account vara :varacc ){
          
          
          

        if (vara.Phone !=  trigger.oldMap.get ( vara.id ).Phone){
              varmap.put(vara.id,vara); 
                        
        }


   }

if(varmap.size() > 0){



         listcontact = [SELECT AccountId, phone FROM Contact Where AccountId in: varmap.keyset() ];


if(listcontact.size() > 0){


        for(Contact con : listcontact ){

               con.Phone = varmap.get(con.AccountId).phone;
                   
           
}
 update listcontact ;  

}

   

 }

}
}