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
MaggieSumitMaggieSumit 

How to update one check field on VF page Load.

Hi,
I want to update one field,once the vf page will be loaded.
Or 
Is there any way to update a field once the user click sites link.

Thanks
Ahmad J. KoubeissyAhmad J. Koubeissy
you can do the update in the contructor, attach the page code for more detail
GulshanRajGulshanRaj
Hi Sumit,

Please follow sample code:
VF page:
<apex:page action="{!createAccount}" controller="test5Controller" >
  
</apex:page>
Controller:
public with sharing class test5Controller {
    public void createAccount()
    {
        Account acc = new Account();
        acc.Name ='Test Name1';
        insert acc;
    }
}


Please let me know if you have any question.


Thanks
Gulshan Raj
 
Ahmad J. KoubeissyAhmad J. Koubeissy
you can the action parameter in VF page to call the method
<apex:page action="{!createAccount}" controller="test5Controller" action="{!createAccount}">

</apex:page>

Thanks for marking as best answer
 
MaggieSumitMaggieSumit
Thanks 
I have writen this code:
  1. public class ControllerFeedback {
  2.     public void init() {
  3.         Id ids = ApexPages.currentPage().getParameters().get('id');    
  4.         system.debug('Id'+ids);
  5.         alu_Opportunity_Matching__c obj = [select id, Name,Application_Status__c FROM alu_Opportunity_Matching__c WHERE id = :ids];        
  6.         obj.Application_Status__c = 'Withdrawn';
  7.         Update obj; 
  8.         return;        
  9.     }
  10. }
 
  1. <apex:page controller="ControllerFeedback" action="{!init}"></apex:page>
Its working but when I load page two time.
GulshanRajGulshanRaj
Hi Sumit,

No need to load page two times. It calls action as soon as page get load.

Thanks
Gulshan Raj