+ Start a Discussion
Orion@gmail.comOrion@gmail.com 

Case Wizard

The code below is for a complicated Case Wizard. The first page currently works where two different values are entered in as search criteria to pull up records in a customer object called STS Asset. After the record or multiply records are selected the user must select a Case Record Type and also select who the contact should be in the case. Then the values of those selections are passed to the next page. Right now I am missing the create of a customer object called Case Asset. 

 

This page needs to create a new Case Asset, a new Case, and a new STS Asset if one is not found. Case Asset is a many to many object that links STS Asset and Case. This is only page one of the wizard. Once this page is completed then I will be posting page two. I have been working on this for months and even tried the help of a consulting firm and still haven't completed it. If you need anything clarified please let me know.

 

 

public class CaseWizard {

    private  List<RecordType> m_recordTypes;
    
    public String SelectedRecordType { get; set;}
    
    /* Variable declarations */

    public List<cSTS_Asset> stsaList {get; set;}                                 // Wrapper class which stores contact data and a boolean flag.
    public Boolean selectAllCheckbox {get; set;}                                  // Stores checkbox data.

    public String PTNs { get; set; }                                              // PTNS
    public String ESNs { get; set; }                                              // ESNs

    public Case SelectedCase { get; set; }
    
    public boolean displayboxes;

    public List<STS_Asset__c> results = new List<STS_Asset__c>();                                     // Contact search results.
//    public List<STS_Asset__c> selectedstsapage1 = new List<STS_Asset__c>();             // Selcted Contacts
    /* End of Variable declarations */
    public Contact ContactStub {get; set;}
    
    public CaseWizard(ApexPages.StandardController controller) {
        /* Constructor Function. The campaign id is captured in this function */
        SelectedCase = (Case) controller.getRecord();
        
        ContactStub = new Contact();
        
        try {
            m_recordTypes = [Select r.Name, r.Id, r.Description From RecordType r Where IsActive = true And SobjectType = 'Case'];
        }
        catch (Exception e) {
            System.debug(System.LoggingLevel.ERROR, 'Error finding Record Types ' + e);
        }
    }

    /*End of Getter and Setter methods */
    /* Method to Search the contact database to fetch the query results */
    public Pagereference stsasearch() {
        stsaList = new List<cSTS_Asset>();
        System.debug(PTNs);
        System.debug(ESNs);

        List<STS_Asset__c> assets = null;
     
        List<String> ptnList = extractParamsFromDelimitedList(PTNs, ' ');
        List<String> esnList = extractParamsFromDelimitedList(ESNs, ' ');
     
        if (ptnList.size() == 0 && esnList.size() == 0) {
            assets = new List<STS_Asset__c>();
        }
        else if (ptnList.size() == 0) {
            assets = Database.query(buildSoql('select Name,FIrst_Name__c,Last_Name__c,ESN_SIM__c,Id from STS_Asset__c where ', esnList, 'ESN_SIM__C like \'', true));
        }
        else if (esnList.size() == 0) {
            assets = Database.query(buildSoql('select Name,FIrst_Name__c,Last_Name__c,ESN_SIM__c,Id from STS_Asset__c where ', ptnList, 'Name like \'', true));
        }
        else {
            String soqlString = buildSoql('select Name,FIrst_Name__c,Last_Name__c,ESN_SIM__c,Id from STS_Asset__c where ', esnList, 'ESN_SIM__C like \'', true);
            assets = Database.query(buildSoql(soqlString, ptnList, 'Name like \'', false));
        }
     
        for(STS_Asset__c c : assets) {
            stsaList.add(new cSTS_Asset(c));
        }
        return null;
    }
    /* End of method */

    /* Method for returning the contact search results to the UI */
    public List<cSTS_Asset> getresults() {
        return stsaList;
    }
    /* End of Method */
    
    /* Wrapper class to contain contact record and a boolean flag */
    public class cSTS_Asset {
        public STS_Asset__c con {get; set;}
        public Boolean selected {get; set;}

        /*This is the contructor method. When we create a new cContact object we pass a
        Contact that is set to the con property. We also set the selected value to false*/
        public cSTS_Asset (STS_Asset__c c) {
            con = c;
            selected = false;
        }
    }
    /* end of Wrapper class */
    
    public List<SelectOption> getRecordTypes() {
        List<SelectOption> options = new List<SelectOption>();
        if (m_recordTypes == null) {
            return options;
        }
        
        for (RecordType rt : m_recordTypes) {
            options.add(new SelectOption(rt.Id, rt.Name));
        }
        return options;
    }

    /* Method to cancel the entire process */
    public Pagereference Cancel() {
        Pagereference p = null;
        
        if (SelectedCase != null && SelectedCase.Id != null) {
            p = new Pagereference('/' + SelectedCase.Id);
        }
        else {
            p = new PageReference('/');
        }
        
        return p;
    }

    public static String buildSoql (String startSoql, List<String> params, String whereClause, boolean firstParam) {
        boolean isFirstParam = firstParam;
        String sqlClause = startSoql;
        for (String param : params) {
            if (!isFirstParam) {
                sqlClause = sqlClause + ' OR ';
            }
            sqlClause = sqlClause + whereClause + param + '%\'';
            isFirstParam = false;
        }
        System.debug(sqlClause);
        return sqlClause;
    }

    public static List<String> extractParamsFromDelimitedList(String input, String delimiter) {
        List<String> values = new List<String>();

        input = input == null ? '' : input.trim();
        delimiter = delimiter == null ? ' ' : delimiter;

        if (delimiter == '') {
            values.add(input);
            return values;
        }
  
        Integer inputindex = input.indexOf(delimiter);
        while (inputindex > -1) {
            if (inputindex == 0) {
                if (input.length() > 1) {
                    input = input.substring(1).trim();
                }
                else {
                    input = '';
                }
                inputindex = input.indexOf(delimiter);
                continue;
            }
            else {
                String value = input.substring(0, inputindex).trim();
                values.add(value);
                if (inputindex == input.length() - 1) {
                    input = '';
                }
                else {
                    input = input.substring(inputindex++).trim();
                }
                inputindex = input.indexOf(delimiter);
            }
        }
  
        if (input != '')
            values.add(input);

        return values;
    }

    public PageReference next() {
        System.debug(System.LoggingLevel.DEBUG, 'In Next');
        
        PageReference pr = Page.CaseWizardPage2;
        List<String> params = new List<String>();
        
        for (cSTS_Asset theasset : getResults()) {
            if (theasset.selected)
                params.add(theasset.con.Id);
        }

        String parameters = '';
        boolean firstParam = true;
        for (String param : params) {
            if (!firstParam)
                parameters = parameters + ',';

            parameters = parameters + param;
            firstParam = false;
        }
    
        pr.getParameters().put('ids', parameters);
        
        // This tells us that the Contact Id 
        if (ContactStub.ReportsToId != null) {
            pr.getParameters().put('contactid', ContactStub.ReportsToId);
        }
        
        if (SelectedRecordType != null) {
            pr.getParameters().put('recordtype', SelectedRecordType);
        }   
        return pr;
    }
}

 

<apex:page standardcontroller="Case" extensions="CaseWizard" >
<!-- Javascript function to check all rows in the table -->
<script>
function checkAll(cb)
{
   var inputElem = document.getElementsByTagName("input");
   for(var i=0;i<inputElem.length;i++)
     {
             if(inputElem[i].id.indexOf("selectLine1")!=-1)
                   inputElem[i].checked = cb.checked;
      }
}
</script>
<!-- End of Javascript function -->
<apex:form >
<apex:sectionHeader title="Step 1" subtitle="Select PTN Numbers to Open a Case"/>
<apex:pageblock >
<apex:pageBlockSection title="Search Consumer by PTN Number or ESN Number" columns="1"></apex:pageBlockSection>

<!-- Div to give a colored box effect -->

<div style="border-width:8px;border-style:solid;border-color:white;">

    <!-- Panel grid to display boxes o accept user input values -->
    <apex:panelGrid columns="2">
        <apex:outputLabel style="font-weight:bold;" value="PTN Number" ></apex:outputLabel>
        <apex:inputTextArea value="{!PTNs}"/>
        <apex:outputLabel style="font-weight:bold;" value="ESN Number" ></apex:outputLabel>
        <apex:inputTextArea value="{!ESNs}"/>
    </apex:panelGrid>
    <!-- End of panelgrid -->
    <!-- Div to position the commandbutton appropriately -->
        <div style="position:relative;left:75px;">
             <apex:commandButton value="Search" action="{!stsasearch}" />
        </div>
    <!-- End of div -->
        <br/>
</div>

<!-- End of colored box div -->
    <br/>

<!-- Display search results -->
<apex:pageblocksection columns="1" title="Search results" rendered="{!NOT(ISNULL(results))}" >
  <apex:outputpanel id="stsalist">

        <apex:pageBlockTable value="{!results}" var="STS_Asset">
             <apex:column >
                <apex:facet name="header">
                    <apex:inputCheckbox onclick="checkAll(this)"/>
                </apex:facet>
                    <apex:inputCheckbox value="{!STS_Asset.selected}" id="selectLine1"/>
            </apex:column>
            <apex:column headervalue="PTN Number">
                <apex:outputtext value="{!STS_Asset.con.Name}"/>
            </apex:column>
            <apex:column headervalue="First Name">
                <apex:outputtext value="{!STS_Asset.con.FIrst_Name__c}"/>
            </apex:column>
            <apex:column headervalue="Last Name">
                <apex:outputtext value="{!STS_Asset.con.Last_Name__c}"/>
            </apex:column>
            <apex:column headervalue="ESN/SIM Number">
                <apex:outputtext value="{!STS_Asset.con.ESN_SIM__c}"/>
            </apex:column>
        </apex:pageBlockTable>  <br/><br/>
        
        <apex:pageBlock title="Select the appropriate Record Type to describe the issue."> 
            <apex:outputLabel value="Record Type" for="recordtypes"/> 
            <p> </p>
            <apex:selectList value="{!SelectedRecordType}" multiselect="false">
               <apex:selectOptions value="{!RecordTypes}"/>
            </apex:selectList>
         <br/><br/>
       </apex:pageBlock>
       
         <apex:pageBlock title="Message Center: Who should be contacted regarding this case?"> 
            <DIV align="center">
            <u><i><big>Use this section to identify who should be contacted for communications regarding the case.</big></i></u> <br/> 
            </DIV>
         <DIV align="center">   
         <b>STS Asset Only: </b> Check mark the Asset box if the STS Asset should be contacted.
         <b>Contact Only: </b> Look up the appropriate Contact if the corporate contact should be sent a notification.
         <b>Both: </b> Or fill in both if the STS Asset and the Contact should be sent notifications.
         </DIV>
         <p> </p>
         <apex:pageBlockSectionItem >
            <apex:outputLabel value="Contact" for="theLookup"/>
            <apex:inputField id="theLookup" value="{!ContactStub.ReportsToId}"/>
        </apex:pageBlockSectionItem>  
        </apex:pageBlock>
</apex:outputpanel>
</apex:pageblocksection>

<!-- End of search results -->

<!-- Commandbutton to proceed to next screen -->
<div style="position:relative;left:75px;">
<apex:commandButton value="Next" action="{!next}"/>
      
  </div>
<!-- End of Commandbutton -->
</apex:pageblock>
</apex:form>
</apex:page>