+ Start a Discussion
Art SaberArt Saber 

edit multiple objects from one vf page

Please help! Just started SFDC development. I've tried so many ways and looked at previously asked questions but can't figure out how to get the code right for an extension to a standardcontroller to be able to edit fields from Account and Opportunity on on VF page. 

VF Page User-added imageWhat does the extension have to look like for the VF page to update the Account fields??
Best Answer chosen by Art Saber
Pankaj MehraPankaj Mehra
Hi Art Saber,

It would look like this
 
Public class CreditExtensionThree {

  Public Opportuntiy opportuntiy {get;set;}  

  public  CreditExtensionThree(ApexPages.StandardController stdCltr) {
     opportuntiy = (Opportuntiy) stdCltr.getRecord();
  }

  public void SaveRecord() {
    
    update opportuntiy;

    Account acc = new Account(Id = opportuntiy.AccountId);
    acc.SiteDesc = opportuntiy.Account.SiteDesc;
    acc.Client__c = opportuntiy.Account.Client__c;
    update acc;
  }
}



thanks


 

All Answers

Harish RamachandruniHarish Ramachandruni
Hi,


show me extention code .



Regards,
Harish.R.
Pankaj MehraPankaj Mehra
Hi Art Saber,

It would look like this
 
Public class CreditExtensionThree {

  Public Opportuntiy opportuntiy {get;set;}  

  public  CreditExtensionThree(ApexPages.StandardController stdCltr) {
     opportuntiy = (Opportuntiy) stdCltr.getRecord();
  }

  public void SaveRecord() {
    
    update opportuntiy;

    Account acc = new Account(Id = opportuntiy.AccountId);
    acc.SiteDesc = opportuntiy.Account.SiteDesc;
    acc.Client__c = opportuntiy.Account.Client__c;
    update acc;
  }
}



thanks


 
This was selected as the best answer
Art SaberArt Saber
Hi Pankaj,

Thank you for submitted your reply. I used your reply but the account fields are not updating on Account. Was I suppose to change anything on the VF page?

Thank you
 
Pankaj MehraPankaj Mehra
Hi Art Saber,

You need to change the save method to point to "SaveRecord", that the only change you need to do.

Thanks
Art SaberArt Saber
Thank you the fields are updating on the object! Sorry I do have one more question, a new issue: when clicking on save, it doesn't redirect back to the opportunity page. How may I go about fixing that?
Pankaj MehraPankaj Mehra
Hi Art Saber,

update return type of method from void to Pagereference and add following line at the end of method

return new Pagereference('/'+opportunity.id);
Art SaberArt Saber
I've appreciated your help with the above.  It works now. Now I'm working on the code coverage haha.
Art SaberArt Saber
Everything is working great. Thankyou.