• Orion@gmail.com
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies

I can't figure out how to handle this issues. We have a problem where we have to calculate and compare time. Basically an order has to be placed in submitted status before 12:00 pm if the shipping address is eastern time. We have to report on our SLAs for orders by timezone. 

 

So an order is recieved 8:00 am pacific time and must be submitted by changing the status to Submitted before 12:00 pm. We are trying to report how many orders are put in the submitted status after 12:00pm to report how many orders went out of the SLA. I hope this describes it. Right now we are using a series of formula and check box fields. I was thinking there might be a different way. Any suggestions are welcomed.

 

Thanks,

 

Rachael

I found a trigger in the Developer Cookbook. The trigger looks at a case being entered to check if an entitlement has been assigned to the case. If the case has no entitlement then it checks the contact or account associated to see if they have an entitlement. I love the trigger however I need it to do one other function. If no entitlement is found then create an entitlement for the Account associated. Please help on this as it is holding us up in deploying the Entitlement process.

 

 

trigger defaultEntitlement on Case (Before Insert, Before Update) {
   /*
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   */
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for
            }
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)
}

 

 

Please let me know what other information is needed. I really could use some help trying to solve it.

 

I really want to deploy the entitlements process since it would assist with both order SLAs and Case SLAs however we have one really big problem. The Entitlements can only viewed when assigned to the Account. In a typical business environment this would work fine but for our needs it doesn't work. We resell Sprint services and phones to coporations however we get orders from individuals that would not tied to an account. Due to other restrictions the individual's name would have to the Account name. 

 

We are trying to implement the Entitlements based on the type of problem that is being reported. All our customers/clients recieved the same service however the process per problem is different itself. This is just as important as the account level. I could use some suggestions on the best implementation that doesn't require entering an entitlement for 1300 plus accounts and creating a logistics nightmare. 

 

Thanks,

 

Rachael

Please help write test code for the following trigger:

 

 

trigger ApplyContractDiscount on QuoteLineItem (before insert, before update) 
{         
    for (QuoteLineItem isContract:trigger.new) 
    {      
        // Build SQL string returning the contract with the highest end date
        string strSQL1 = 'SELECT c.AccountId, c.Account.Id, c.Discount_Level__c, c.EndDate FROM Contract c WHERE c.AccountId = ';
        strSQL1 += '\'';
        strSQL1 += isContract.Account_ID_Formula__c;
        strSQL1 += '\'';
        strSQL1 += ' ORDER BY c.EndDate DESC LIMIT 1';
            
        List<Contract> L = Database.query(strSQL1);
    
        if (L.size() > 0) //Does a contract exist?
        {
            Contract A = Database.query(strSQL1);
            isContract.Discount = A.Discount_Level__c;
        }

        isContract.UnitPrice = isContract.ListPrice;
        isContract.Discount = 0;
    }
}

 

 

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>

 

 

 

 

I can't figure out how to handle this issues. We have a problem where we have to calculate and compare time. Basically an order has to be placed in submitted status before 12:00 pm if the shipping address is eastern time. We have to report on our SLAs for orders by timezone. 

 

So an order is recieved 8:00 am pacific time and must be submitted by changing the status to Submitted before 12:00 pm. We are trying to report how many orders are put in the submitted status after 12:00pm to report how many orders went out of the SLA. I hope this describes it. Right now we are using a series of formula and check box fields. I was thinking there might be a different way. Any suggestions are welcomed.

 

Thanks,

 

Rachael

I have the following VF page using custom objects and a custom controller to generate the page content:-

 

<apex:page showHeader="false" controller="PageRenderer" title="FusionExperience" >
<apex:stylesheet value="{!URLFOR($Resource.fusionexperience, 'css/reset.css')}" />
<apex:stylesheet value="{!URLFOR($Resource.fusionexperience, 'css/style.css')}" />
<apex:stylesheet value="{!URLFOR($Resource.fusionexperience, 'css/type.css')}" />

<!-- CONTENT -->
<div id="content">

    <!-- PAGE ELEMENTS (PASSED THROUGH PGL PAGE PARAM) -->
    <apex:outputPanel rendered="{!NOT(elements.size=0)}">
        <apex:repeat var="el" value="{!elements}" >

            <!-- (LIST OF) CONTENT TYPE -->

            <apex:variable var="clRender" value="{!NOT(ISNULL(el.Content_Type__c))}" />
            <apex:outputPanel rendered="{!clRender}" layout="block" styleClass="box">
                <div class="viewdiv {!el.Box_Size__c}">
                    <!-- BOX TITLE -->
                    <!-- uses content type title -->
                    <div class="latestnews headline">
                        <h3>{!el.content_type__r.Title__c}</h3>
                    </div>
                    
                    <!-- //BOX TITLE -->
                    
                    <!-- OUTLINED BOX -->
                    <div class="latestnews content">
                        <ul class="latestnews">
                            <apex:variable var="noItems" value="{!el.content_type__r.List_Length__c}" />
                            <apex:repeat var="cl" value="{!ContentList}" >
 
                                <!-- Only list content of THIS content type -->
                                <apex:variable var="clRender" value="{!AND(noItems>0, cl.Content_Type__c=el.Content_Type__c)}" />
                                <apex:outputPanel rendered="{!clRender}" >
                        
                                    <!-- IMAGE/URL -->
                        
                                    <apex:variable var="isPDF" value="{!IF(cl.Attachment__c='pdf', cl.Use_Attachment__c, false)}"/>
                                    <apex:variable var="isFlash" value="{!IF(cl.Attachment__c='flash', cl.Use_Attachment__c, false)}"/>
                                    <apex:variable var="readMore" value="{!IF(cl.content_type__r.Read_More__c,true,false)}" />

                                    <!-- establish pdf string -->
                                    <apex:variable var="pdfLink" value="{!IF(isPDF, IF(cl.Attachments.size=0, '', cl.Attachments[0].id), '')}"/>
                                    <apex:variable var="pdfLink" value="/servlet/servlet.FileDownload?file={!pdfLink}" />
                                
                                    <!-- establish flash string -->
                                    <apex:variable var="flashLink" value="{!IF(isFlash, IF(cl.Attachments.size=0, '', cl.Attachments[0].id), '')}"/>
                                    <apex:variable var="flashLink" value="fe?id={!cl.Content_Type__r.Read_More_Dest__c}&mov={!flashLink}" />
                        
                                    <!-- establish URL string for new page view -->
                                    <apex:variable var="itmLink" value="{!IF(cl.Contents__r.size=0, '', cl.Contents__r[0].id)}" />
                                    <apex:variable var="itmLink" value="fe?id={!cl.Content_Type__r.Read_More_Dest__c}&itm={!itmLink}" />
                                    <apex:variable var="itmLink" value="{!IF(cl.Contents__r.size=0, '', itmLink)}" />

                                     <apex:variable var="link" value="{!IF(readMore, IF(isPDF, pdfLink, IF(isFlash, flashLink, itmLink)), cl.URL_Link__c)}" />


                                     <!-- TEXT BLOCK -->
                                    <li class="latestnews">
                                        <a href="{!link}" class="latestnews">{!cl.Heading__c}<br /></a>
                                        <apex:variable var="sRender" value="{!NOT(cl.Content_Type__r.Synopsis_Length__c=0)}" />
                                        <apex:outputText rendered="{!sRender}" escape="false" styleClass="latestintro" value="{!LEFT(cl.Synopsis__c,cl.Content_Type__r.Synopsis_Length__c)}..." />
                                    </li>
                                    <apex:variable var="noItems" value="{!noItems-1}" />
                                </apex:outputPanel>
                            </apex:repeat>
                        </ul>
                    </div>
                </div>
             </apex:outputPanel>
 
              <!-- //CONTENT TYPE -->
                     
        </apex:repeat>
    </apex:outputPanel>

<!-- //CONTENT -->

</div>
</apex:page>

 

However, it's not formatting correctly in the browser, and when looking at the html code produced:

 

(see here) http://www.yatecourtbarn.adsl24.co.uk/images/test.html

 

It seems to be producing code that is missing the closing </div> tags, and hence screwing-up the css layout.

 

AFAICS, it has opening nested <div> tags for 'box', 'box-left viewdiv', and 'content latestnews', but only closes two of them before the next opening sequence.

 

Has anyone come across this before and/or can anyone offer a solution?

 

Thanks.

 

I'm looking for some Sample APEX that would, upon Case creation, do a lookup to the Contacts Account and find the Entitlement Associated to the Account.  In my case, there will only ever be one Entitlement associated to an Account so the results would return one record.  I need this entitlement to be automatically associated to the Case and automatically kick off.  Essentially, when a case is created, I need the entitlement to kick off immediately.  Does anyone have any sample APEX I can look at that might point me in the right direction.

We've enabled our entitlement module and we need to be able to auto-generate an entitlement id when a new account is created.  Does anyone know how this should be written, looks as if the only way to set this up would be through Apex. 

 

Currently our feed brings over external account information and if that account doesn't already exist, it creates a new account in Salesforce (ID field in the Accounts object).  Ideally we're trying to figure out how an associated entitlement id could be created with the Account ID, generating an entitlement object (Entitlement_c) with the same name as the Account name. 

 

If anyone has tried this approach or if more details are needed, please let me know.

 

    Hi All! I have two formulas. The first one I created to keep a running ticker of the number of days, hours, & minutes a case has been open. It looks like this:

Text(FLOOR(NOW() - CreatedDate)) &" "&"day(s)"&" "&Text(FLOOR(MOD( (NOW() - CreatedDate) * 24 ,24))) &" "&"hrs"&" "&Text( FLOOR(MOD(((NOW() - CreatedDate) * 24)*60 ,60)))&" "&"min")
The second formula I got off the boards and it keeps track in business hrs the number of hrs a case has been open:

IF(AND(MOD(TODAY()-DATE(1900,1,7),7)< (NOW() - CreatedDate ), ((NOW() - CreatedDate )<7)),((NOW() - CreatedDate)-2) * 24, ((NOW() - CreatedDate)-(2 * ((NOW() - CreatedDate)/7))) * 24)

Both of these formulas work great, however, I would like to have the business hrs formula in the same format as the first formula. So it would be business hrs in days, hrs, and minutes. Does anyone have any ideas?? I keep playing with it but it is always off.