0

I'm trying to avoid hardcoding Ids in my code. I want to do that with Custom Settings List 'TypeList' - got there field to hold record type ids 'TypeId'. Is there any chance to use Custom Setting List in SELECT FROM WHERE ?

Class:

public with sharing class contrlller{
        public Id Current_Acc_Id {get;set;}

        public contrlller(ApexPages.StandardController controller) {
            Case caseObject = (Case)controller.getRecord();
            Current_Acc_Id = caseObject.AccountId;
        }
        List<TypeList__C> mcs = TypeList__c.getall().values();

        public List<Case> getrelatedCases(){
            List <case> conList = new List<Case>();
            for(Case relatedCase: [SELECT CaseNumber, Case_Type__c, OwnerId, Origin, Id FROM Case WHERE (RecordTypeId != '01220000000VD9K' AND IsClosed!=True AND AccountId =:Current_Acc_Id)]){
                conList.add(relatedCase); 
            }
            return conList;
        }
    }

VP

    <apex:page standardController="Case" extensions="contrlller">
 <apex:includeScript value="/support/console/29.0/integration.js"/>
    <script type="text/javascript">           
        function openSubTab(recId){
            var redirectUrl = recId;
            if (sforce.console.isInConsole()) {
                sforce.console.getEnclosingTabId(function(enclosingResult){
                    sforce.console.getEnclosingPrimaryTabId(function(primaryResult){
                        sforce.console.openSubtab(primaryResult.id, redirectUrl, true, '', null);
                    });
                });
            } else {
                window.open('/'+redirectUrl,'name',
                'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');

            }
        }        
    </script>

   <apex:form >
    <apex:pageblock >
       <apex:pageBlockTable value="{!relatedCases}" var="val">
        {!Case.AccountId}
         <apex:column headerValue="CaseNumber">              
                <a href="#" onclick="openSubTab('{!val.Id}');">{!val.CaseNumber}</a>
            </apex:column>     

         <apex:facet name="header"><apex:outputText value="Open Customer Service Cases " style="color:red"/></apex:facet>          
         <apex:column headerValue="CaseNumber">     
         <apex:commandLink value="{!val.CaseNumber}" action="/console?{!val.Id}" target="_blank" />
         </apex:column>
         <apex:column value="{!val.RecordTypeId}"/>      
         <apex:column value="{!val.Case_Type__c}"/>
         <apex:column value="{!val.OwnerId}"/>




       </apex:pageBlockTable> 
    </apex:pageblock>
  </apex:form>
</apex:page>
2
  • Your custom setting will store Id of multiple record types or only one?
    – Ankita
    Commented Jul 18, 2017 at 7:47
  • Now only one but in future it will store more of them.
    – Jacob K
    Commented Jul 18, 2017 at 7:53

1 Answer 1

0

If your custom setting has only one record, then you can fetch the all the values and store the record Id in one variable and use it for comparison.

List<TypeList__C> mcs = TypeList__c.getall().values();
Id recordTypeId;
if(mcs != null && mcs.size() > 0){
    recordTypeId = mcs[0].TypeId;
}

public List<Case> getrelatedCases(){
   List <case> conList = new List<Case>();
   for(Case relatedCase: [SELECT CaseNumber, Case_Type__c, OwnerId, Origin, Id FROM Case WHERE (RecordTypeId !=:recordTypeId  AND IsClosed!=True AND AccountId =:Current_Acc_Id)]){
       conList.add(relatedCase); 
   }
   return conList;
} 

Suggestion: Instead of storing the record type Id values in custom settings, query it from RecordType object or using RecordTypeInfo class.

Refer RecordTypeInfo class in Salesforce

1
  • Got this with different way. Just created UniqueId formula field on my Case, This field is checkbox If(RecordTypeId=="01220000000VD9K",true,false) and i just added in my code WHERE UniqueId__c != True. In future i can switch If with Case and add more ids.
    – Jacob K
    Commented Jul 18, 2017 at 10:47

You must log in to answer this question.

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