You need to sign in to do that
Don't have an account?

Simple Controller - update related object field?
How would I update a lookup's field from this controller? The value is saved, but no DML is performed because I think my save method is incorrect.
Vendor_Name__c on Service_Request__c is a lookup to Contact.
public class VendorInvoiceController { private final Service_Request__c srf; public Contact vendor; public string orderId = ApexPages.currentPage().getParameters().get('orderId'); public string vendorId = ApexPages.currentPage().getParameters().get('vendorId'); public string rfpId = ApexPages.currentPage().getParameters().get('rfpId'); //Constructor public VendorInvoiceController(){ srf = [SELECT Vendor_Name__r.Name, Vendor_Name__r.Id, Vendor_Name__r.MailingStreet, Vendor_Name__r.Payment_Info__c, Vendor_Invoiced_Received__c FROM Service_Request__c WHERE Id =: orderId]; } public Service_Request__c getSrf() { return srf; } public pageReference save(){ vendor = [select Id from Contact where Id =: vendorId]; //vendor.payment_info__c = 'test'; update vendor; return null; } public pageReference updateMe() { update srf; return null; } }
Page
<apex:page controller="VendorInvoiceController" showHeader="false" sidebar="false"> <apex:form > <apex:pageMessages /> <apex:pageBlock tabstyle="Service_Request__c"> <apex:pageBlockSection title="Payment Information" id="test"> <apex:outputfield value="{!srf.Vendor_Name__r.MailingStreet}"/> <apex:outputfield value="{!srf.Vendor_Name__r.Payment_Info__c}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Update Me"> <apex:inputField value="{!srf.Vendor_Name__r.Payment_Info__c}"/> //re-renders but no DML? <apex:inputField value="{!srf.Vendor_Invoiced_Received__c}"/> </apex:pageBlockSection> <apex:commandButton value="Update Address" action="{!save}" rerender="test"/> <apex:commandbutton value="Update Me" action="{!updateMe}"/> </apex:pageBlock> </apex:form> </apex:page>
Instead of
public Service_Request__c getSrf() {
I would use
Then for my vendor update - i would go from:
to
and have
public Contact vendor {get;set;}?
So, i wouldn't want to do srf.vendor_name__r.field then?
No just replace that code block that I mentioned and everything else should work. Using the default getter/setter methods is sufficient for what you need.
No, that doesn't seem to work. It's updated in the visualforce page - but the object (Related contact) is not updated.
the update call in my save button calls to update vendor; but is that kind of operation a problem?