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
Cherry@appsharkCherry@appshark 

To update a field

 

 

How to update a field when the user  clicks on a custom button?

 

I tried in java script, but cant sort it out.

 

Please help me ...........

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

As per my understanding, below is the answer

 

I hope you might be using apex:commandButton or a normal html button using input tag

If you use apex:commandButton, you have to use the action attribute there.

<apex:commandButton action="{!updateFunc}" value="Update"/>

Now, this updateFunc should be defined in your custom controller, something like this

public PageReference updateFunc()

{

 //your update code here

 return null;

}

 

If you are using <input type="button" form of tag, then the code should be something as below,

<input type="button" name="update" value="Update" onclick="return updateFuntion();"/>

Now you have to use actionFunction tag 

<apex:actionFunction name="updateFunction" action="{!updateFunc}" rerender="Ids If Any"/>

In the above tag, name should be same that i used in onclick of input tag.

In Controller you should declare your action

public PageReference updateFunc()

{

//your update code here

return null;

}

 

Let me know if you have any issues.

All Answers

Imran MohammedImran Mohammed

As per my understanding, below is the answer

 

I hope you might be using apex:commandButton or a normal html button using input tag

If you use apex:commandButton, you have to use the action attribute there.

<apex:commandButton action="{!updateFunc}" value="Update"/>

Now, this updateFunc should be defined in your custom controller, something like this

public PageReference updateFunc()

{

 //your update code here

 return null;

}

 

If you are using <input type="button" form of tag, then the code should be something as below,

<input type="button" name="update" value="Update" onclick="return updateFuntion();"/>

Now you have to use actionFunction tag 

<apex:actionFunction name="updateFunction" action="{!updateFunc}" rerender="Ids If Any"/>

In the above tag, name should be same that i used in onclick of input tag.

In Controller you should declare your action

public PageReference updateFunc()

{

//your update code here

return null;

}

 

Let me know if you have any issues.

This was selected as the best answer
Cherry@appsharkCherry@appshark

Can we do it through customisation?