You need to sign in to do that
Don't have an account?
Supriyo Ghosh 5
Hot to Generate Autonumber In APex
HI,
I have a apex class which is generating a report based on Query.I want to give a numer for that set of records.So for each time report generation a new number will be generate and post that number in all the record fetch in that report.How to do that.Please help.
Class
public with sharing class GenerateDtfCase {
public GenerateDtfCase() {
}
//public POSDetails__c customerObj{get;set;}
Public List<Case> customerObj = new List<Case>();
public List<Case> getcustomerObj(){return customerObj;}
Public List<Employee_Master__c> Emp{get;set;}
public String branchcode{get;set;}
public Case trnObj = new case();
public Case gettrnObj(){return trnObj;}
public list<case> upcase = new list<case>();
//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, 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 );
//ModifyCase();
}
public void ModifyCase() {
System.debug('====customerObj:'+customerObj);
for(Case c: [select id,CaseNumber,Branch_name__c,Account_Name__c,Proposal_Detail__c,Branch_Code__c,DTF_No2__c,Principal_code__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 (RecordTypeID ='012O00000005BMS' AND DTF_Creation_Date__c=null AND Vertical__c =: trnObj.Vertical__c AND Principal_code__c =: trnObj.Principal_code__c)]) {
customerObj.add(c);
case ics = new case();
ics.id = c.id;
ics.DTF_Creation_Date__c = System.today();
ics.DTF_No2__c = c.Branch_Code__c +c.CaseNumber+ System.today();
upcase.add(ics);
}
if(!upcase.isempty()){
update upcase;
}
}
Public pageReference exportReport(){
PageReference pg=ApexPages.currentPage();
// System.Debug('>>>>>>>>>>>Date Test:>>>>>>>>>>'+trnObj.DTF_genarated_date__c);
pg=new PageReference('/apex/Genarate_DTF_for_Case?vert='+ trnObj.Vertical__c +'&pricode='+trnObj.Principal_code__c);
pg.setredirect(true);
return pg;
}
}
I have a apex class which is generating a report based on Query.I want to give a numer for that set of records.So for each time report generation a new number will be generate and post that number in all the record fetch in that report.How to do that.Please help.
Class
public with sharing class GenerateDtfCase {
public GenerateDtfCase() {
}
//public POSDetails__c customerObj{get;set;}
Public List<Case> customerObj = new List<Case>();
public List<Case> getcustomerObj(){return customerObj;}
Public List<Employee_Master__c> Emp{get;set;}
public String branchcode{get;set;}
public Case trnObj = new case();
public Case gettrnObj(){return trnObj;}
public list<case> upcase = new list<case>();
//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, 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 );
//ModifyCase();
}
public void ModifyCase() {
System.debug('====customerObj:'+customerObj);
for(Case c: [select id,CaseNumber,Branch_name__c,Account_Name__c,Proposal_Detail__c,Branch_Code__c,DTF_No2__c,Principal_code__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 (RecordTypeID ='012O00000005BMS' AND DTF_Creation_Date__c=null AND Vertical__c =: trnObj.Vertical__c AND Principal_code__c =: trnObj.Principal_code__c)]) {
customerObj.add(c);
case ics = new case();
ics.id = c.id;
ics.DTF_Creation_Date__c = System.today();
ics.DTF_No2__c = c.Branch_Code__c +c.CaseNumber+ System.today();
upcase.add(ics);
}
if(!upcase.isempty()){
update upcase;
}
}
Public pageReference exportReport(){
PageReference pg=ApexPages.currentPage();
// System.Debug('>>>>>>>>>>>Date Test:>>>>>>>>>>'+trnObj.DTF_genarated_date__c);
pg=new PageReference('/apex/Genarate_DTF_for_Case?vert='+ trnObj.Vertical__c +'&pricode='+trnObj.Principal_code__c);
pg.setredirect(true);
return pg;
}
}