+ Start a Discussion
DhairyaDhairya 

Controller Method

Hi,

 

  I have to custom obj (1) Project (2) Budget with lookup relationship (1 Proj can have multiple budgets)

 

  One VF page with stdcontroller budget__c and extension accepting value for month and budget value.

 

  Command Button {!addMore}.

 

   Here i wrote a class method 

 

 

public PageReference addMore() {
     
    database.Insert(budget1);
// Would like to Rollup sum of all budgetvalue related to the project but test1__c never get updated.
    if(budget1.Value__c!=Null && budget1.PMO_Project__r.test1__C!=Null)
               budget1.PMO_Project__r.test1__c=budget1.PMO_Project__r.test1__c + budget1.Value__c;
    
    ApexPages.StandardController budgetController = new ApexPages.StandardController(budget1);
    return budgetController.save();
    //return page.budgetDetail;
}
I need accumulated budget value at Project level.
Appreciate your help.
Thanks,
Dhairya

 

JaydipJaydip

I would replace below line

budget1.PMO_Project__r.test1__c=budget1.PMO_Project__r.test1__c + budget1.Value__c;

 

with

 

project prj=[Select test1__c from project where id=:budget1.PMO_Project__c];

 

prj.test1__c +=budget1.Value__c;

 

update prj;

 

Thanks