You need to sign in to do that
Don't have an account?
![Deepu sfdc Deepu sfdc](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Creating a Visualforce page on opportunities
Hello Guys,
When i change opportunity status to “closed one” for selected opportunities, On click of save it will update opportunity status as well as Account status as well.
Please tell me how to achieve this.
Thanks in Advance,
Deepu
When i change opportunity status to “closed one” for selected opportunities, On click of save it will update opportunity status as well as Account status as well.
Please tell me how to achieve this.
Thanks in Advance,
Deepu
After updating Opportunity status on the visualforce page controller, use the successfully updated opportunity Id list say selectedOppList.
Now query AccountIds using selectOppList as below -
Set<Id> AccountIds = new Set<Id>();
List<Account> accountsToBeUpdated = new List<Account>();
for(Opportunity opp : selectOppList ){
AccountIds.add(opp.AccountId);
}
if(AccountIds.Size() > 0){
accountsToBeUpdated = [Select Id. Status from Account] where Id IN: AccountIds];
}
for(Account acc : accountsToBeUpdated ){
acc.Status = 'your status';
}
if(accountsToBeUpdated.Size() > 0){
update accountsToBeUpdated;
}
Another way is to update opportunity inside page controller and update its account in the trigger on update of Opportunity.
Hope this helps.
All Answers
From the Visualforce page for opportunity, update the opportunity.
And create a trigger on opportunity object that will check for opportunity status update, if status is "closed one" then update the account related to that opportunity.
You can get the related account id of opportunity like: Get the account from this AccountID and update the status of account.
Hope this helps.
After updating Opportunity status on the visualforce page controller, use the successfully updated opportunity Id list say selectedOppList.
Now query AccountIds using selectOppList as below -
Set<Id> AccountIds = new Set<Id>();
List<Account> accountsToBeUpdated = new List<Account>();
for(Opportunity opp : selectOppList ){
AccountIds.add(opp.AccountId);
}
if(AccountIds.Size() > 0){
accountsToBeUpdated = [Select Id. Status from Account] where Id IN: AccountIds];
}
for(Account acc : accountsToBeUpdated ){
acc.Status = 'your status';
}
if(accountsToBeUpdated.Size() > 0){
update accountsToBeUpdated;
}
Another way is to update opportunity inside page controller and update its account in the trigger on update of Opportunity.
Hope this helps.