function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Supriyo Ghosh 5Supriyo Ghosh 5 

field update and filter

Hi,
I have a apex class.I want to add a fiter criteria if vertical__c=='test' from case object then update date__c=system.today();.Please help.

Class
public with sharing class GenerateDtfCase {
Public List<Case> customerObj{get;set;}
  Public List<Employee_Master__c> Emp{get;set;}
  public String branchcode{get;set;}
public Date Today { get { return Date.today(); }}
    public GenerateDtfCase(ApexPages.StandardController controller) {
      try
        {
            Emp= [Select e.User__r.Id, e.User__c, e.Id, e.Branch_Code__r.BranchCode__c, e.Branch_Code__r.Cash_inCounter_Limit__c, 
                  e.Branch_Code__r.Cash_in_Safe_Limit__c, e.Branch_Code__r.Name, e.Branch_Code__c 
                  From Employee_Master__c e where User__r.Id = : UserInfo.getUserId() and Active__c= : true  limit 1];
            
            if(Emp[0].Branch_Code__r.BranchCode__c!= null)
            {
               
                branchcode=Emp[0].Branch_Code__r.Name;
            }else{
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Branch mapping found in Employee master for the logged in user.  Please contact the system administrator to get it corrected.'));
            }
        }catch(exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No mapping record found in Employee Master for the Logged in user. Please contact the system administrator to get it corrected.'));
        }
    system.debug('branch code:'+branchcode);
    
    
    customerObj = [select id,CaseNumber,Branch_name__c,Account_Name__c,Proposal_Detail__c,Policy_Number__c,Creation_Date__c,Document_List__c,Vertical__c,DTF_Creation_Date__c,Effective_date_of_coverage__c,Request_Type__c,Supporting_Document__c 
    FROM Case WHERE Vertical__c='LI' AND RecordType.ID ='012O00000005BMS' AND created_date__c=true ];
        
//customerObj = [select id, Name, Complete_Status__c, Branch_name__c,Branch__r.Name , Creation_Date__c, Document_List__c, Vertical__c, Status__c, DTF_Creation_Date__c, Effective_date_of_coverage__c, Policy_No__c, proposal_Application_no__c, proposal_Name__c, Request_Type__c, Request_Type_new_del__c, Branch__c, Supporting_Document_del__c, OwnerId from POSDetails__c where (Vertical__c = 'LI'and Branch__r.Name =:branchcode)];
system.debug('test query branch:'+branchcode);
system.debug('test query customerObj:'+customerObj );

    }
    
    public GenerateDtfCase() {
      
    } 

}
Mahesh DMahesh D
Hi Supriyo,

Please find the below code:
 
customerObj = [select id,CaseNumber,Branch_name__c,Account_Name__c,Proposal_Detail__c,Policy_Number__c,Creation_Date__c,Document_List__c,Vertical__c,DTF_Creation_Date__c,Effective_date_of_coverage__c,Request_Type__c,Supporting_Document__c 
    FROM Case WHERE Vertical__c='LI' AND RecordType.ID ='012O00000005BMS' AND created_date__c=true ];


--------------------



public void modifyCase() {
     for(Case c: customerObj) {
          if(c.Vertical__c == 'LI')
               c.Date__c = System.today(); 
     }
     update customerObj
}
Here I just wrote a method to update the above retrieved list of cases.

Regards,
Mahesh
Amit Chaudhary 8Amit Chaudhary 8
Please try below code

public with sharing class GenerateDtfCase
{
    Public List<Case> customerObj{get;set;}
    Public List<Employee_Master__c> Emp{get;set;}
    public String branchcode{get;set;}
    public Date Today { get { return Date.today(); }}
    public GenerateDtfCase(ApexPages.StandardController controller)
    {
      try
        {
            Emp= [Select e.User__r.Id, e.User__c, e.Id, e.Branch_Code__r.BranchCode__c, e.Branch_Code__r.Cash_inCounter_Limit__c,
                  e.Branch_Code__r.Cash_in_Safe_Limit__c, e.Branch_Code__r.Name, e.Branch_Code__c
                  From Employee_Master__c e where User__r.Id = : UserInfo.getUserId() and Active__c= : true  limit 1];
            
            if(Emp[0].Branch_Code__r.BranchCode__c!= null)
            {
               
                branchcode=Emp[0].Branch_Code__r.Name;
            }else{
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Branch mapping found in Employee master for the logged in user.  Please contact the system administrator to get it corrected.'));
            }
        }catch(exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No mapping record found in Employee Master for the Logged in user. Please contact the system administrator to get it corrected.'));
        }
    system.debug('branch code:'+branchcode);
    
    
    customerObj = [select id,CaseNumber,Branch_name__c,Account_Name__c,Proposal_Detail__c,Policy_Number__c,Creation_Date__c,Document_List__c,Vertical__c,DTF_Creation_Date__c,Effective_date_of_coverage__c,Request_Type__c,Supporting_Document__c
    FROM Case WHERE Vertical__c='test' AND RecordType.ID ='012O00000005BMS' AND created_date__c=true ];

     for(Case c: customerObj)
     {
        if(c.Vertical__c == 'test')
        {        
               c.Date__c = System.today();
        }       
     }
     update customerObj    


    }
    
    public GenerateDtfCase() {
      
    }

}

Let us know if this will help you
Supriyo Ghosh 5Supriyo Ghosh 5
Hi,

I have written the code but after execution of the query filds is not updating.

public with sharing class GenerateDtfCase {
//public POSDetails__c customerObj{get;set;}
Public List<Case> customerObj{get;set;}
  Public List<Employee_Master__c> Emp{get;set;}
  public String branchcode{get;set;} 
  //public String cityBranch {get;set;} 
public Date Today { get { return Date.today(); }}
    public GenerateDtfCase(ApexPages.StandardController controller) {
      try
        {
            Emp= [Select e.User__r.Id, e.User__c, e.Id, e.Branch_Code__r.BranchCode__c, e.Branch_Code__r.Cash_inCounter_Limit__c, 
                  e.Branch_Code__r.Cash_in_Safe_Limit__c, e.Branch_Code__r.Name, e.Branch_Code__c 
                  From Employee_Master__c e where User__r.Id = : UserInfo.getUserId() and Active__c= : true  limit 1];
            
            if(Emp[0].Branch_Code__r.BranchCode__c!= null)
            {
               
                branchcode=Emp[0].Branch_Code__r.Name;
            }else{
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Branch mapping found in Employee master for the logged in user.  Please contact the system administrator to get it corrected.'));
            }
        }catch(exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No mapping record found in Employee Master for the Logged in user. Please contact the system administrator to get it corrected.'));
        }
    system.debug('branch code:'+branchcode);
    
    //customerObj = [select id, Name,Complete_Status__c,Branch_name__c,Creation_Date__c,Document_List__c,Vertical__c,Status__c,DTF_Creation_Date__c,Effective_date_of_coverage__c,Policy_No__c,proposal_Application_no__c,proposal_Name__c,Request_Type__c,Request_Type_new_del__c,Branch__c ,Supporting_Document_del__c 
    //FROM POSDetails__c WHERE Vertical__c='LI' AND Branch__r.Name =:branchcode];
    customerObj = [select id,CaseNumber,Branch_name__c,Account_Name__c,Proposal_Detail__c,Policy_Number__c,Creation_Date__c,Document_List__c,Vertical__c,DTF_Creation_Date__c,Effective_date_of_coverage__c,Request_Type__c,Supporting_Document__c 
    FROM Case WHERE Vertical__c='LI' AND RecordType.ID ='012O00000005BMS' AND created_date__c=true ];
        
//customerObj = [select id, Name, Complete_Status__c, Branch_name__c,Branch__r.Name , Creation_Date__c, Document_List__c, Vertical__c, Status__c, DTF_Creation_Date__c, Effective_date_of_coverage__c, Policy_No__c, proposal_Application_no__c, proposal_Name__c, Request_Type__c, Request_Type_new_del__c, Branch__c, Supporting_Document_del__c, OwnerId from POSDetails__c where (Vertical__c = 'LI'and Branch__r.Name =:branchcode)];
system.debug('test query branch:'+branchcode);
system.debug('test query customerObj:'+customerObj );

    }
    
    public GenerateDtfCase() {
      for(Case c: customerObj) {
          if(c.Vertical__c == 'LI')
          customerObj = [select id,CaseNumber,Branch_name__c,Account_Name__c,Proposal_Detail__c,Policy_Number__c,Creation_Date__c,Document_List__c,Vertical__c,DTF_Creation_Date__c,Effective_date_of_coverage__c,Request_Type__c,Supporting_Document__c 
    FROM Case WHERE Vertical__c='LI' AND RecordType.ID ='012O00000005BMS' AND created_date__c=true ];
               c.DTF_Creation_Date__c = System.today();
     }
     update customerObj;

    } 

}
Mahesh DMahesh D
@Amit,

As the SOQL is in Constructor, we can't use the DML statement inside the Constructor. Hence we have to write a new method and update the Case records.

Regards,
Mahesh
Mahesh DMahesh D
Hi Supriyo,

I am not sure which Constructor you are using it from your Controller. Also you can't perform the DML operations inside the Constructor.

Please write a new method and try to update the Case list by looping through it.

Regards,
Mahesh
Supriyo Ghosh 5Supriyo Ghosh 5
@Mahesh

I have written the code but after execution of te query the field is not updating.Please help.
Mahesh DMahesh D
Please paste your VF page. Also using the above panel (< >) to copy the code.

Regards,
Mahesh
Supriyo Ghosh 5Supriyo Ghosh 5
vf page

<apex:page id="pg" renderAs="PDF"  standardController="Case" extensions="GenerateDtfCase" sidebar="false" showHeader="false"  standardStylesheets="false">
<center><h4 style="font: 100% Verdana, Arial, Helvetica, sans-serif;
">Peerless Financial products Distribution  Limited</h4></center>
<br/><br/>
<apex:pageMessages />


<apex:form id="thisForm">



<center>
<table border="1" width="100%" height="50px" cellpadding="0" cellspacing="0" >

<tr>
    <th colspan="7"><center style="
    font-weight: normal;
">DTF-Policy Owner Service</center></th>
  </tr>
<tr>
<th></th>
<th></th>
<th colspan="3" style="
    font-weight: normal;
">PB-</th>
<th colspan="3" style="
    font-weight: normal;
">Date-<apex:outputText value="{0,date}">
    <apex:param value="{!Today}" />
</apex:outputText></th>
</tr>
<tr>
<td>Sl no</td>
<td>Proposal no</td>
<td>Proposer Name</td>
<td>Work type</td>
<td>Documents</td>
<td>Document Lists</td>
<td>Remarks</td>
</tr>
<apex:repeat value="{!customerObj }" var="case" id="theEquipmentRepeat">
<tr>

<td> <apex:outputText value="{!case.CaseNumber}" />
</td>
<td> <apex:outputText value="{!case.Proposal_Detail__c}" />
</td>
<td> <apex:outputText value="{!case.Account_Name__c}" />
</td>
<td> <apex:outputText value="{!case.Request_Type__c}" />
</td>
<td> <apex:outputText value="{!case.Supporting_Document__c }"/>
</td>

<td> <apex:outputText value="{!case.Document_List__c}"/>
</td>
<td> <apex:outputText value=""/>
</td>



</tr>
</apex:repeat>


</table>
<apex:commandButton value="Print"  onClick="window.print()"/>
</center>
        
</apex:form>
</apex:page>
Mahesh DMahesh D
Hi Supriyo,

Please use the below sample code to call the method which will update the Case records.
 
<apex:commandButton value="Modify Cases" action="{!modifyCase}" />
Whenever user clicks on the above button then it will update the case records.

Please do let me know if it helps.

Regards,
Mahesh
Supriyo Ghosh 5Supriyo Ghosh 5
it trowing below error.

Unknown method 'CaseStandardController.ModifyCase()'

vf page
<apex:page id="pg" renderAs="PDF"  standardController="Case" extensions="GenerateDtfCase" sidebar="false" showHeader="false"  standardStylesheets="false">
<center><h4 style="font: 100% Verdana, Arial, Helvetica, sans-serif;
">Peerless Financial products Distribution  Limited</h4></center>
<br/><br/>
<apex:pageMessages />


<apex:form id="thisForm">



<center>
<table border="1" width="100%" height="50px" cellpadding="0" cellspacing="0" >

<tr>
    <th colspan="7"><center style="
    font-weight: normal;
">DTF-Policy Owner Service</center></th>
  </tr>
<tr>
<th></th>
<th></th>
<th colspan="3" style="
    font-weight: normal;
">PB-</th>
<th colspan="3" style="
    font-weight: normal;
">Date-<apex:outputText value="{0,date}">
    <apex:param value="{!Today}" />
</apex:outputText></th>
</tr>
<tr>
<td>Sl no</td>
<td>Proposal no</td>
<td>Proposer Name</td>
<td>Work type</td>
<td>Documents</td>
<td>Document Lists</td>
<td>Remarks</td>
</tr>
<apex:repeat value="{!customerObj }" var="case" id="theEquipmentRepeat">
<tr>

<td> <apex:outputText value="{!case.CaseNumber}" />
</td>
<td> <apex:outputText value="{!case.Proposal_Detail__c}" />
</td>
<td> <apex:outputText value="{!case.Account_Name__c}" />
</td>
<td> <apex:outputText value="{!case.Request_Type__c}" />
</td>
<td> <apex:outputText value="{!case.Supporting_Document__c }"/>
</td>

<td> <apex:outputText value="{!case.Document_List__c}"/>
</td>
<td> <apex:outputText value=""/>
</td>




</tr>
</apex:repeat>


</table>
<apex:commandButton value="Modify Case" action="{!ModifyCase}" />
<apex:commandButton value="Print"  onClick="window.print()"/>
</center>
        
</apex:form>
</apex:page>
Mahesh DMahesh D
Please add the below code in your controller.
 
public void modifyCase() {
     for(Case c: customerObj) {
          if(c.Vertical__c == 'LI')
               c.Date__c = System.today(); 
     }
    update customerObj
}

Regards,
Mahesh
Supriyo Ghosh 5Supriyo Ghosh 5
@mahesh

record is still not updating.
Mahesh DMahesh D
 
public void modifyCase() {
     System.debug('====customerObj:'+customerObj);
     for(Case c: customerObj) {
          if(c.Vertical__c == 'LI')
               c.Date__c = System.today(); 
     }
    update customerObj
}

Please enable the debug log and paste it here.

Regards,
Mahesh