+ Start a Discussion

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?



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
update tr;