+ Start a Discussion

Make primary button..help me...

Hi Guys,
 i have one agreement objcet , in this object some records will be there, in these records i want to select one primary record...
please help on this.. below is my code ..
<apex:page standardController="Apttus__APTS_Agreement__c" extensions="OnLoadController">
<apex:form >

        <apex:outputText value="{!Apttus__APTS_Agreement__c.Name}" rendered="false"/>
        <apex:outputText value="{!Apttus__APTS_Agreement__c.Apttus__Account__c}" rendered="false"/>
        <apex:outputText value="{!Apttus__APTS_Agreement__c.APTS_Primary__c}" rendered="false"/>

 <apex:commandButton id="btnOnLoad" action="{!onLoad}" value="On Load" style="display: none" />
            var btnOnLoad = document.getElementById("{!$Component.btnOnLoad}");
        <apex:pageBlock mode="edit" rendered="{!hasErrors}" >
            <apex:pageMessages />
            <apex:pageBlockButtons location="bottom" >
                    <apex:commandButton action="{!doMakePrimary}" value="Make Primary"/>  
                <apex:commandButton action="{!doCancel}" value="{!$Label.apttus__apts_agreement__cancel}" immediate="true"/>
        // register to invoke the function after the page load
        var hasErrors = "{!hasErrors}";
        if (hasErrors.toLowerCase() == 'false') {
            window.onload = function() { 
                // on load

and Controller code...
public class OnLoadController {

    public Apttus__APTS_Agreement__c agreement { get; set; }

    public OnLoadController(ApexPages.StandardController stdController){
        this.agreement = (Apttus__APTS_Agreement__c)stdController.getRecord();
    public void doMakePrimary(){
        Apttus__APTS_Agreement__c agreementRec = [SELECT ID, APTS_Primary__c, Apttus__Related_Opportunity__c FROM Apttus__APTS_Agreement__c WHERE ID =: agreement.Id];
        //add If condition to check other agreement records
        agreementRec.APTS_Primary__c = TRUE;
        insert agreementRec;
    public PageReference doCancel() {
        PageReference agreementPage = new PageReference('/' + agreement.id);
        return agreementPage;
    public String hasErrors { get; set; }

    public PageReference onLoad() {
             update agreement;
        return null;


Thanks In Advance... 
Soundar Raj PonpandiSoundar Raj Ponpandi
HI Shambavi,

Why You not try Standard Functionality by the Visualforce page (By The Following Code). In Your Code you are going to Select and update the Primay Checkbox as well, i m right?? then you can use the following code.

---------------------      VF Pag       -------------------
<apex:page standardController="Apttus_APTS_Agreement__c" recordSetVar="ap" >
    <apex:form >
        <apex:pageblock title="Apptus">
            <apex:pageBlockTable title="Apptus Test" value="{!ap}" var="a">
                <apex:column value="{!a.Name}"/>
                <apex:column headerValue="Primary">
                    <apex:inputCheckbox value="{!a.APTS_Primary__c}"/>
            <apex:pageblockButtons >
                <apex:commandButton action="{!Save}" value="Update Apttus"  />
                <apex:commandButton action="{!Cancel}" value="Cancel"  />

Hi Sunder ,
Thanks for giving reply...i agree with you.:) but,
my requirement is "Click on “Make Primary” button on agreement record. This will set a checkbox “Primary” to true. This would be an indicator for the system to start sync of deal information & status updates to the related opportunity."
 so i created one formula filed like "make primary " and i inseted one "button" image in "static resoure"(Make Primary){ means action }. so now , once click on that make primary button or action that record should be make primary..please find out below screen shot ... and help on this...User-added image