You need to sign in to do that
Don't have an account?
Dhairya
Apex method with update
Hi,
{!addMore} is a coomand button action (VF) and blow code is a part of exdtension. I am getting current record in variable named budget1 of type Budget__C.
I would like to calculate total budget value at project level on field test1__c on Project__C object.
Question is creation of budget record working fine but budger related project field (test1__c) is not populated.
//Budget Record Save
public PageReference addMore()
{
database.Insert(budget1);
if(budget1.value__c!=Null && budget1.PMO_Project__r.test1__c!=null )
{
budget1.PMO_Project__r.test1__c = 'test';
projects__c project = [select
name from projects__c where projects__c.id=:budget1.PMO_Project__r.Id] ;
update(project)
}
ApexPages.StandardController budgetController = new ApexPages.StandardController(budget1);
return budgetController.save();
//return page.budgetDetail;
}
Appreciate Your Help,
Dhairya
Please try below one
//Budget Record Save
public PageReference addMore() {
database.Insert(budget1);
if(budget1.value__c!=Null && budget1.PMO_Project__r.test1__c!=null ) {
//budget1.PMO_Project__r.test1__c = 'test';
projects__c project = [select name from projects__c where projects__c.id=:budget1.PMO_Project__r.Id] ;
project.test1__c = 'test';
update project;
}
ApexPages.StandardController budgetController = new ApexPages.StandardController(budget1);
return budgetController.save();
//return page.budgetDetail;
}
Let me know if you are still facing any issues.
Hey Crmtech21,
Thanks for your prompt reply but its not updating test1__C (Text) value on project__C obj.
Do u have any other idea?
thanks,
dhairya
I believe the if clause is not satisfied.
if(budget1.value__c!=Null && budget1.PMO_Project__r.test1__c!=null )
Please check if the both of the above conditions are true. I think the second budget1.PMO_Project__r.test1__c is not satisfied and the code within the if statement is not executing.
with best,
Thanks for your reply.
I will try that.
Dhairya