+ Start a Discussion
IvanB@LMIvanB@LM 

Controller save method ?

Hi, experts - 

Reletively new to SF, I got  a standard controller on contact and thru extension I am trying to save records to a custom

object. Records are retrived on a VF page. It is not saving. Snippet:

 

List<customobj__c> cp =
 [select id from customobj__c limit 1
];

public void save() {update cp; }

save is called as

<apex:commandButton id="update" action="{!save}" value="Save"

 

If it is an invalid design, how can I write to another object when controller is on contact object ?

Thanks!

ministe_2003ministe_2003

It looks to me as if your commandbutton is overriding the standard save functionality of your standardController.

If you're using a standardController, standard functionality can be added to buttons by calling actions like "{!save}" and "{!cancel}" without having to write any code - it's all handled by the standardController.  Because you're also using an extension I think you'll need to rename your function to something else (say, saveCustomObject) then update the action parameter on your button to call that function instead of "{!save}".   That way you can be sure that the button is calling your function instead of the standardController's Save function

IvanB@LMIvanB@LM

Tried by changing to custom_save(); no luck. It is not saving !

aballardaballard

What is your page displaying?     Since the only thing you retrieve in your select is the id, that would be the only thing you could display/update.   And you can't change the id of an object.....

 

 

IvanB@LMIvanB@LM

I am pulling in field which trying to update thru inline edit

 

<apex:dataTable value="{!demo}" var="pitem">
<apex:column >
Hobby: <apex:outputField value="{!pitem.cp.E5__c}">
<apex:inlineEditSupport event="ondblclick" showOnEdit="update"/>
</apex:outputField>
</apex:column>
</apex:dataTable>

 

Thanks,

ministe_2003ministe_2003

You'll need to add any fields that you want to update to your query.  If you're only doing SELECT Id FROM... then it'll only be able to process the Id.  If you want to update and other fields on that object then you'll need to add them to your SELECT list.