function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cnewmancnewman 

Change Save Button Behavior - Update Separate Object

Hi All,

New to Salesforce Developmet and trying to replace the save button on my Visualforce page with a custom save button.

This is a custom object related to an Opportunity, when this object is saved I need it to update the lookup field on the opportunity to the ID of the object I'm saving.

Is this possible, can I update a seperate object when I save?

Thanks


sunil_kumarsunil_kumar
Hi,

Yes, you can update seperate object in one method call.

First inserting related custom object in apex method, then put a query on opportunity and then update the record id of inserted record in opportunity.

For example, custom object name is Temp__c
Temp__c tr=new Temp__c();
//field assignments
insert tr;

//put query to fetch opportunity and store it in variable say opp or if you already have in apex variable the directly assign value
//assume field name in opportunity is parent__c, then
opp.parent__c=tr.id;
update tr;