+ Start a Discussion
Arnas BaronasArnas Baronas 

Custom button to update field on click

Hello,
I am new to salesforce and I would like to know how to create custom button to update record's field value on click.
Should I use lightning component + apex code or is it possible achieve it without code?
Example - what I am trying to achieve:
FieldName:  Times clicked
FieldValue = 0 + 1 time clicked // sObject_c.TimesClicked++
Best Answer chosen by Arnas Baronas
ASIF ALIASIF ALI
If you want to save record, You can do it in visualforce too
<apex:page standardController="Account">
    <apex:form>
    
    <apex:pageBlock title="Edit Account">
        <apex:pageBlockSection>
            <apex:inputField value="{! Account.Name }"/>        
        </apex:pageBlockSection>
        <apex:pageBlockButtons>
            <apex:commandButton action="{! save }" value="Save" />        
        </apex:pageBlockButtons>
    </apex:pageBlock>
    
    </apex:form>
</apex:page>

This code saves the account record with Account name,
for your problem , you can achieve it by using javascript

All Answers

ASIF ALIASIF ALI
If you want to save record, You can do it in visualforce too
<apex:page standardController="Account">
    <apex:form>
    
    <apex:pageBlock title="Edit Account">
        <apex:pageBlockSection>
            <apex:inputField value="{! Account.Name }"/>        
        </apex:pageBlockSection>
        <apex:pageBlockButtons>
            <apex:commandButton action="{! save }" value="Save" />        
        </apex:pageBlockButtons>
    </apex:pageBlock>
    
    </apex:form>
</apex:page>

This code saves the account record with Account name,
for your problem , you can achieve it by using javascript
This was selected as the best answer
Arnas BaronasArnas Baronas
I have made onclick JavaScript custom button to do that, but I need alternative for lightning expirience, because only salesfroce classic supports javascript custom buttons. I need that button to be at the record's page.
satish palsatish pal
Hi Arnas Baronas,
You need to create a custom URL button this button is visible in both classic and lightning.

Thanks
Satish Pal