0

I've created a VF page which is used in console.

When I click on "Assign" button it will check the value in both fields.

If user field value in both field then it will throw error.

The problme is somtime error is displaying fine. Some time error is displaying very small amount of time. Sometime error is not displaying.

What could be the reason.

Vf Page

<apex:page controller="consoleVFcont" tabStyle="Case" sidebar="false">
    <apex:includeScript value="/support/console/32.0/integration.js"/>
    <apex:includeScript value="{!URLFOR($Resource.Bootstrap_335,'/js/jquery_1_11_3.min.js')}"/>   
    <apex:includeScript value="/support/console/42.0/integration.js"/>
    <apex:includeScript value="/soap/ajax/38.0/connection.js"/>
    <apex:includeScript value="{!URLFOR($Resource.cnx__CnxSfdcResources,'js/ConnectsIntegrationAPI.min.js')}"/>

   <apex:outputpanel id="page">
    <script>

        function closeTab() {

            sforce.console.getFocusedPrimaryTabId(function (result) {
                console.log(result);
                    sforce.console.closeTab(result.id);
                    sforce.console.setCustomConsoleComponentVisible(false);   
            });
        }

        function refreshTab() {

            sforce.console.getFocusedPrimaryTabId(function (result) {
                console.log(result);

                if({!closePage}){
                    sforce.console.refreshNavigationTab();   
                    sforce.console.closeTab(result.id);
                    sforce.console.setCustomConsoleComponentVisible(false);   
                }else if({!refreshPage}){
                    sforce.console.refreshPrimaryTabById
                    (result.id,true,refreshSuccess);
                }
            });
        }

        var refreshSuccess = function refreshSuccess(result) {

            if (result.success == true) {
                //alert('Primary refresh');
            } else {
                alert("{!$Label.ConsoleTabRefreshError}");
            }
        };            



</script> 
        <A HREF="#" onClick="closeTab();">
           Click here to close this tab</A> 

        <apex:form id="fm">
            <apex:actionFunction action="{!validateCaseIds}" name="validateCaseIds" reRender="fm,errmsg" status="status">
                <apex:param name="caseId" value="" assignTo="{!caseId}" />              
            </apex:actionFunction>



            <apex:actionstatus id="status" startText="Requesting...">
               <apex:facet name="start">
                   <c:ProgressComponent Message="Processing..." Width="104px" Height="104px"/>
               </apex:facet>

               <apex:facet name="stop"/>
            </apex:actionstatus>



            <apex:pageBlock id="pb" > 
                <apex:pageBlockButtons location="bottom" rendered="{!!ISNULL(c)}">
                    <apex:commandButton action="{!assignQueue}" onclick="retrieveTabCaseId();" onComplete="refreshTab();" value="Assign" reRender="fm,errmsg" status="status" style="width:100px" />            
                </apex:pageBlockButtons>  
                <apex:outputPanel id="errmsg">
                <apex:pageMessages id="pageMessage" ></apex:pageMessages> 
                </apex:outputPanel>

                <apex:outputPanel rendered="{!ISNULL(c)}"> 
                    <apex:pageMessage summary="{!$Label.Case_ReassignCaseInstructions}" severity="warning" strength="0"/>     
                </apex:outputPanel>

                 <apex:outputPanel rendered="{!!ISNULL(c)}"> 
                    <apex:pageMessage summary="{!$Label.Assign_Submission_to_appropriate_Queue}" severity="info" strength="0"/>  
                    <apex:pageBlockSection columns="1" collapsible="false" >

                <apex:pageBlockSectionItem >
                    <apex:outputLabel >{!$Label.Queue_Name}</apex:outputLabel>
                            <apex:selectList value="{!queueId}" multiselect="false" size="1" >
                                <apex:selectOption itemLabel="--Not Selected--" itemValue=""/>
                                <apex:selectOptions value="{!QueueSobjectList}"/>
                            </apex:selectList> 
                        </apex:pageBlockSectionItem> 

                  <apex:pageBlockSectionItem >
                    <apex:outputLabel >{!$Label.User_Name}</apex:outputLabel>
                    <apex:selectList value="{!userId}" multiselect="false" size="1" >
                        <apex:selectOption itemLabel="--Not Selected--" itemValue=""/>
                            <apex:selectOptions value="{!UserList}"/>
                    </apex:selectList> 
                    </apex:pageBlockSectionItem> 
                    </apex:pageBlockSection>                        
                </apex:outputPanel> 
            </apex:pageBlock>
        </apex:form>
    </apex:outputpanel>

    <script>

     var retrieveTabCaseId = function (result) {
        sforce.console.getFocusedPrimaryTabObjectId(function (result) {
        console.log(result);
            validateCaseIds(result.id);
        });
    };
    sforce.console.onCustomConsoleComponentButtonClicked(retrieveTabCaseId);
    </script>      

</apex:page>

Controller :

public without sharing class consoleVFcont {
public Case c { get; set; } 
public case newCase{get; set;}
public Boolean refreshPage {get; set; }
public Boolean closePage {get; set; }
public String queueId { get; set; }
public String userId { get; set; } 
public String caseId { get; set; } 
private List<SelectOption> queueListOptions = new List<SelectOption>();
private List<SelectOption> userOption= new List<SelectOption>();

public consoleVFcont(){ //constructor
    for(QueueSobject q : [SELECT QueueId,Queue.DeveloperName,Queue.Name FROM QueueSobject
                            WHERE SobjectType = 'Case'
                            ORDER BY Queue.DeveloperName]){
        queueListOptions.add(new SelectOption(q.QueueId,q.Queue.Name));
    }

    for(User u : [SELECT Id,Name FROM User/* WHERE  cnx__Agent_ID__c != ''
                        ORDER BY Name*/]){

        userOption.add(new SelectOption(u.Id,u.Name));
    }   
    newCase = new Case();     
}

public List<SelectOption> getQueueSobjectList(){
    return queueListOptions;
}

public List<SelectOption> getUserList(){
    return userOption;
}


public void validateCaseIds(){
    c = null;
    for(Case item : [Select Id, OwnerId  from Case where Id =: caseId]){
        c = item;
    }    
    return;
}    

public void assignQueue(){
    c = new Case();
    for(Case item : [Select Id, OwnerId  from Case where Id =: caseId]){
        c = item;
    }
    if(c == null ) return;
    System.debug(queueId + ' Queue and User' +userId );

    if(queueId!=null  && userId!=null){
    System.debug(queueId + ' Inside ' +userId );
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select either a Queue or a User')); 
    queueId=null;
    userId=null;
    return;
    }

  ID currentOwner = c.OwnerId;
  refreshPage = false;
  closePage = false;      
  if(queueId!=null && queueId!=''){
      c.OwnerId = queueId;
     } else if (userId!=null && userId!=''){
        c.OwnerId = '00G3D000000hVmI';
        //c.Assigned_To__c=  userId; 
    }

      try{
        update c;
        queueId=null;
        userId=null;
      Case c1 = [Select Id, OwnerId from Case where Id =: c.Id];
            if(c1.OwnerId != currentOwner){
      closePage = true;    
         }
      refreshPage = true;          
    }catch(exception e){

      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
    }     
}    

}

Can you please help.

1 Answer 1

2

The reason is this reRender="fm,errmsg". Because you are rerendering your apex:pagemessage from both commandButton and actionfunction.

But there execution order is not fixed(as both making separate request.) sometimes when your button throw error the action function refresh the section and the error goes away. and sometime the actionfunction refresh first so you get proper message.

To handle this situation you need to be careful with the rerender section. You can use reRender=none" from actionfunction if you don't need it or rereneder the required section and not the complete page.

2
  • actually action function calling on page load also, thus we used Rerender in action function as well.
    – user29314
    Apr 5, 2018 at 9:30
  • @user29314 then you need to break it in different section. Apr 5, 2018 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .