I have a vf page and its extensions,I am trying to save the multiple lists of a object against a particular recordtype.But i am unable to fetch the record the record type and then assign to the same object.If you have any idea and then please mention it.Thank you.
public with sharing class LevittAmpBudgetUpdatedCtrl {
public List<Grant_Report__c> grExpenseObjLst{get;set;}
public List<Grant_Report__c> grCashObjLst{get;set;}//Matching fund,Cash Object List
public List<Grant_Report__c> grInKindObjLst{get;set;}//Matching fund,inkind Object List
public Grant_Report__c grObj{get;set;}
public Grant_Approval__c gaObj{get;set;}
private ID ids{get;set;}
public LevittAmpBudgetUpdatedCtrl(ApexPages.StandardController controller) {
//
ids= ApexPages.currentPage().getParameters().get('id'); //
gaObj=new Grant_Approval__c();
grExpenseObjLst= new list<Grant_Report__c>();
grCashObjLst=new List<Grant_Report__c>();
grInKindObjLst=new List<Grant_Report__c>();
RecordType rt= [SELECT id FROM RecordType WHERE Name='Matching Fund Cash'];
System.debug('ssssss'+rt);
for(AMP_Budget_Expense__c exObj:AMP_Budget_Expense__c.getAll().Values()){
grObj=new Grant_Report__c();
grObj.Expense_Category_Label__c=exObj.Expense_Category__c;
grExpenseObjLst.add(grObj);
}
//check if id is not null
if(ids!= null)
{
gaObj = [SELECT id,AMP_Grant_Request_Amount__c,Cash_Match_Total_Amount__c,
InKind_Match_Total_Amount__c,Comment__c FROM Grant_Approval__c WHERE Id= :ids];//
for(Grant_Report__c gr: [select id,Matching_Cash_Source__c,Matching_Cash_Amount__c,Matching_Cash_Commitment__c from Grant_Report__c where Grant_Approval__c=:ids ]) {//get all related grant report cash records
grCashObjLst.add(gr);
}
for(Grant_Report__c gr: [select id,Matching_inKind_Source__c,Matching_inKind_item__c,Matching_inKind_Amount__c,
Matching_inKind_Commitment__c from Grant_Report__c where Grant_Approval__c=:ids ]) {//get all related grant report IN-Kind records
grInKindObjLst.add(gr);
}
for(Grant_Report__c gr: [select id,Expense_Total_Amount__c,Expense_Cash_Amount__c,Expense_InKind_Anount__c,Expense_Category_Label__c from Grant_Report__c where Grant_Approval__c=:ids ]) {//get all related grant report IN-Kind records
grExpenseObjLst.add(gr);
}
}
else{
//default 5 lineitem will come
for(integer i=0; i<5; i++)
{
grObj = new Grant_Report__c();
grCashObjLst.add(grObj);
grInKindObjLst.add(grObj);
}
}
}
//add more row of Matching Funds,Cash
public pageReference addMoreCashFund(){
grObj = new Grant_Report__c();
grCashObjLst.add(grObj);
return null;
}
//add more row of Matching Funds,Cash
public pageReference addMoreInkindFund(){
grObj = new Grant_Report__c();
grInKindObjLst.add(grObj);
return null;
}
Public Pagereference savedoc(){
List<Grant_Report__c> enteredCashGrantReport = new List<Grant_Report__c>();
List<Grant_Report__c> enteredInKindGrantReport = new List<Grant_Report__c>();
List<Grant_Report__c> enteredExpenseReport = new List<Grant_Report__c>();
for(Grant_Report__c gr: grCashObjLst){
if(gr.id==null)
{
gr.Grant_Approval__c= ids;
}
enteredCashGrantReport.add(gr);
}
for(Grant_Report__c gr: grInKindObjLst){
if(gr.id==null)
{
gr.Grant_Approval__c= ids;
}
enteredInKindGrantReport.add(gr);
}
for(Grant_Report__c gr: grExpenseObjLst){
if(gr.id==null)
{
gr.Grant_Approval__c= ids;
}
enteredExpenseReport.add(gr);
}
grExpenseObjLst=null;
try{
upsert gaObj;
upsert enteredCashGrantReport;
upsert enteredInKindGrantReport;
upsert enteredExpenseReport;
}catch(System.DMLException e) {
ApexPages.addMessages(e);
return null;
}
return NULL;
}
public PageReference Back()
{
PageReference startPage=new PageReference('/apex/Network_Calendar');
startPage.setRedirect(true);
return startPage;
}
}
Matching Fund Cash
record type to records in which of the lists in your code?Matching Fund Cash
record type to the records beforeupserting
them in yoursavedoc()
method. If that's the case, checkout my updated answer.