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
GV1GV1 

Need sample code

Hi All

 

I have a VisualForce page embeded as a related list in Opportunity, which takes the Opportunity id and displays certain details.

 

There is a Checkbox in the VF page. when this Checkbox is selected I need to update another object at backend and refresh the entire Opportunity detail page.

 

The VF page is already there, i just have to incorporate this change. Can someone give me some sample code looking at which I can understand how do I use Java script, and how do I update the object with the value of Opportunity ID and the field (on VF page) pervious to the Checkbox.

 

I am a Newbie, any help will be greatly appriciated.

 

Regards

 

Best Answer chosen by Admin (Salesforce Developers) 
GV1GV1

Completed the code. For reference pasting the code here.

 

 

Call the JavaScript via the checkbox

 

<apex:inputCheckbox value="{!res.isApplicantPresent}" disabled="{!res.disableCustAuth}" onclick="checkAuth('{!identification}','{!res.isApplicantPresent}')"/>

 

Inside the <Script> pass the parameter and then call the Apex:actionfunction to call the method in the controller:

function checkAuth(index, currentVal)
    {
  var firstparam =index;
  var secondParam=currentVal;
  if(secondParam)
  callActionfun(firstparam,secondParam);
  }
    <apex:actionfunction name="callActionfun" action="{!urControllermethodname}" rerender="frm">
     <apex:param name="firstparam" value="firstparam" assignto="{!controllervariable}"/>
     <apex:param name="secondParam" value="secondParam" assignto="{!controllervariable}"/>
     </apex:actionfunction>
	 

 

 

All Answers

ShaTShaT
Hi ,

You can call a java script function on click

function checked(){
window.parent.location.href='/{!Opportunity.id}';
}
GV1GV1

Completed the code. For reference pasting the code here.

 

 

Call the JavaScript via the checkbox

 

<apex:inputCheckbox value="{!res.isApplicantPresent}" disabled="{!res.disableCustAuth}" onclick="checkAuth('{!identification}','{!res.isApplicantPresent}')"/>

 

Inside the <Script> pass the parameter and then call the Apex:actionfunction to call the method in the controller:

function checkAuth(index, currentVal)
    {
  var firstparam =index;
  var secondParam=currentVal;
  if(secondParam)
  callActionfun(firstparam,secondParam);
  }
    <apex:actionfunction name="callActionfun" action="{!urControllermethodname}" rerender="frm">
     <apex:param name="firstparam" value="firstparam" assignto="{!controllervariable}"/>
     <apex:param name="secondParam" value="secondParam" assignto="{!controllervariable}"/>
     </apex:actionfunction>
	 

 

 

This was selected as the best answer