2

I am pasting a complete code for anyone reference if they like to resolve it.(Just incase they want to know what i could be missing.)
NOTE: CaseOwnerChanged__c = Checkbox field type

<apex:page standardController="Case" extensions="ChangeCaseOwnerNotificationCtrlr">
   <script type="text/javascript">
        alert('{!Case.Id}');
        window.document.onload= new function(){
        if(({!Case.AccountId == '0013000000bFnBwAAK'} && {!Case.Classification__c =='ASO'})&&           {!Case.CaseOwnerChanged__c}){
                alert("xyz");
            }
            RevertCheckBox('{!Case.OwnerId}');           
       }
    </script>
    <apex:form >
        <apex:actionFunction name="RevertCheckBox" action="{!checkCaseOwner}"> 
            <apex:param id="anode" name="ownerIdVar" value="" assignTo="{!aCaseId}"/>
        </apex:actionFunction>
    </apex:form>
</apex:page>

I am using a check box field a Case Object to check some condition, if its TRUE i am showing a popup (alert!!). But Once the checkbox is used to show the popup, i want to revert it back to false, for which i tried using RevertCheck JS function using ActionFunction, passing the Case.Id to controller, as

public with sharing class ChangeCaseOwnerNotificationCtrlr {
    public static Id aCaseId {get;set;}

    public ChangeCaseOwnerNotificationCtrlr(ApexPages.StandardController controller) {
    }
    public void checkCaseOwner(){
        system.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'+ aCaseId);
        Case c =[SELECT id,CaseOwnerChanged__c from case where id =: aCaseId];
        //Case c = new Case(Id = aCaseId);
        c.CaseOwnerChanged__c=false;
        update c;
    }
  }

But this does not works. Could you please help me this regard.! Would be grateful. (If you want any other details, please revert me back thru the same) Thanks

  • Why you are creating a new Case object in the controller? you need to update a field of current case object isn't it? – highfive Sep 25 '14 at 6:28
  • Yes that's right,. So the reason i am passing on the ID to fetch same Case object I guess. – awat baratarey Sep 25 '14 at 6:33
  • And on top I am not able to get alert('<<<<<<<<<>>>>>>>>'); and system.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'+ aCaseId); in my log. – awat baratarey Sep 25 '14 at 6:33
  • Where you call RevertCheck() JS function? without calling it you can't see alert() you can't see debug statement – highfive Sep 25 '14 at 6:41
  • I referred few similar questions, and as per the solutions, there is no need to call the RevertCheck() from an <apex:ActionFunction>. But I think required while using Remoting, we mention the funtion name to call it on the depending event... like onClick or... – awat baratarey Sep 25 '14 at 6:50
1

If you are using Case standardController and controllerExtension, you no need of passing the case id to the controller. Just bind the Case record with the controller as described in documentation.

Controller:

public with sharing class ChangeCaseOwnerNotificationCtrlr {
    public Case c{get;set;}

    public ChangeCaseOwnerNotificationCtrlr(ApexPages.StandardController controller) {
        this.c = (Case)controller.getRecord();
    }
    public void checkCaseOwner(){
        c.CaseOwnerChanged__c=false;
        update c;
    }
  }

In the visualforce page you no need the <apex:param /> since the loaded case record has been already bonded with the controller. VF Page:

<apex:page standardController="Case" extensions="ChangeCaseOwnerNotificationCtrlr">
   <script type="text/javascript">
        alert('{!Case.Id}');
        window.document.onload= new function(){
        if(({!Case.AccountId == '0013000000bFnBwAAK'} && {!Case.Classification__c =='ASO'})&&           {!Case.CaseOwnerChanged__c}){
                alert("xyz");
            }
            RevertCheckBox();           
       }
    </script>
    <apex:form >
        <apex:actionFunction name="RevertCheckBox" action="{!checkCaseOwner}"> 
        </apex:actionFunction>
    </apex:form>
</apex:page>

Note that you need a valid Case id in the URL to work this page properly since you are using standardController

  • Yes this did helped to query the right Case. But on research i found that, onlaod does not allows to call a method of a controller. In short it's due to Data Records and VF Pages in different servers combine to your UI, thus forbids the call. – awat baratarey Sep 26 '14 at 14:06
  • Oh really?good one for research. But if i have not mistaken i have used onload to call the controller.may be it's with salesforce RPC – highfive Sep 26 '14 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.