• Staci
  • NEWBIE
  • 290 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 194
    Questions
  • 203
    Replies
I'm building a sort of audit vf page for our products and was wondering if there is a way to make this circle(shown), then when a users clicks this circle once and it turns green, click twice and it turns yellow, click 3 times and it turns red.  
User-added image
  • December 16, 2022
  • Like
  • 0
We do not want people to be able to create a case through an email but we do like the functionality of being able to respond to an email from a case comment.  I have WFR/Email Alert set up to send users emails when a comment is added to a case.  I'd like those users to be able to respond to that email and have it go back to the case.  Is that possible?  Please let me know how to configure.
  • November 10, 2022
  • Like
  • 0
I want to make a vf page to look like the below to create records from.  Users will enter the info in like an excel sheet then click save and it will save into a record.  

Ratings will be a dropdown
Ref# & Process/Task will just be the text you see
Frequency a text box
Notes an RTF field

How do I create this mix of fields in a vf page?

User-added image
  • September 23, 2022
  • Like
  • 0
I have the following code to move attachments from the inbound email message into Attachments - we are still in classic

I have 53% coverage right now.  Can't figure out how to get the last half of this code covered.
//test coverage in DSSEmailHandlerTest 
trigger CW_emailAttachmentReassigner on Attachment (before insert) {
        map<id, id> msgIdToParentId = new map<id, id>();
        Attachment[] reparents = new Attachment[]{};
        Schema.sObjectType email = emailmessage.getsobjecttype();
    

        for(Attachment a : trigger.new) {
            if(a.parentid != null){
                //see if the parent is an EmailMessage
                if(a.parentid.getsobjecttype() == EmailMessage.getsObjectType()) {



 //Test code from here down                 
 msgIdToParentId.put(a.parentid, null);
                    reparents.add(a);
                }
            }
        }
        
        if(!reparents.isEmpty()){
            for(EmailMessage em : [select id, parentID from EmailMessage where id =: msgIdToParentId.keyset()]){
                msgIdToParentId.put(em.id, em.parentId);
            }
        
            for(Attachment a : reparents) {
                a.parentId = msgIdToParentId.get(a.parentId);
            }
        }
        
    }
 
@isTest
private class DSSEmailHandlerTest
{
public static Blob createAttachmentBody(){
        String body = 'XXXXXXXXXXXXX';
        return Blob.valueof(body);
    }
    public static testMethod void testmyHandlerTest() 
    {
        Case c = new Case();
        insert c;
        
        Messaging.InboundEmail email = new Messaging.InboundEmail();
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        email.subject = 'ref';
        email.PlainTextBody = 'test body';
        
        // Add a Binary attachment to the email message!
        Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
        attachment.body = blob.valueOf('my attachment content');
        attachment.fileName = 'filename.txt';
        attachment.mimeTypeSubType = 'text/plain';
        email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment };
        
        DSSEmailHandler m = new DSSEmailHandler();
        m.handleInboundEmail(email, env);
     }
     
     
}

 
  • March 17, 2022
  • Like
  • 0
Here's my email handler
global class DSSEmailHandler implements Messaging.InboundEmailHandler {
      global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
   
    
      Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
      if(email.subject.contains('ref'))
      {
            try
            {
                 Case c = new Case();
                  c.ContactId = email.fromAddress;
                  c.recordTypeId = '0121O000001WL0u';
                  c.OwnerId = '00G1O000004lFB4';
                  c.Description = email.plainTextbody;
                  c.Subject = email.subject;
                  insert c;
                  //to save attachment to case
                  for(Messaging.Inboundemail.BinaryAttachment bAttachment:
                  email.binaryAttachments) {
                      Attachment attachment = new Attachment();
                      attachment.Name = bAttachment.fileName;
                      attachment.Body = bAttachment.body;
                      attachment.ParentId = c.Id;
                      insert attachment;
                  }               
                
                  result.success = true;
            }catch (Exception e){
                  result.success = false;
                  result.message = 'Oops, I failed.' + e.getMessage();
            }
              return result;
      }
      return null;
 
  }
  }
Here's the test code
@isTest
private class DSSEmailHandlerTest
{
public static Blob createAttachmentBody(){
        String body = 'XXXXXXXXXXXXX';
        return Blob.valueof(body);
    }
    public static testMethod void testmyHandlerTest() 
    {
        Case c = new Case();
        insert c;
        
        //String cName = [SELECT Name FROM Case WHERE Id = :c.Id LIMIT 1].Name;
        
        Messaging.InboundEmail email = new Messaging.InboundEmail();
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        email.subject = 'ref';
        email.plainTextBody = 'test body';  
        DSSEmailHandler m = new DSSEmailHandler();
        m.handleInboundEmail(email,env);   
        
       // attachment insert
  
        Attachment att = new Attachment(Name = 'XXXXXXXX', Body = Blob.valueof('XXXXXXXXXXXXXX'), ParentId = c.Id);
        insert att;
        

                     
    }
}

I can't get this part covered, I'm at 70% without it
Attachment attachment = new Attachment();
                      attachment.Name = bAttachment.fileName;
                      attachment.Body = bAttachment.body;
                      attachment.ParentId = c.Id;
                      insert attachment;
                  }               
                
                  result.success = true;


 
  • February 16, 2022
  • Like
  • 0
Has anyone automated email alerts?  If so, how? 

This is what I would like.  We have a group of users that rotate about every 3 months and they only want notifications for the worksite they are supporting at that time.  Is there a way for them to click a button or something so be added/removed from an email alert?
  • February 14, 2022
  • Like
  • 0
I'm trying to copy a case comment from emails and i want it to cut off before text A or before text B.  
CaseComment cc = new CaseComment(CommentBody=myCase.Last_email__c.substringbefore('Text A' OR 'Text B'),parentID=caseId);

What is the correct syntax?  This above obviously does not work
  • September 17, 2021
  • Like
  • 0
I have a field that when the radio button is yes, the field appears and needs to be filled in.  I have the title appearing, but the box to fill it in is not showing up.  What am I missing?  I'm just posting the snippet of the rerender and the field that needs to be filled in. User-added image
 
<apex:actionRegion >           
              <apex:selectRadio value="{!selectedOption}">
            
            <apex:selectOption itemValue="Yes" itemLabel="Yes" />
            <apex:selectOption itemValue="No" itemLabel="No" />
            <apex:actionSupport event="onchange" rerender="form" />
        </apex:selectRadio>
        </apex:actionRegion>
               
                            
                                                    
                <apex:panelGrid id="xxx" rendered="{!IF(selectedOption='Yes',True,False)}">
                    <apex:facet name="header">Date</apex:facet>
                    <apex:inputfield value="{!e1.asset.Date__c}" style="width:95px" required="true"/>
                </apex:panelGrid>

 
  • August 18, 2021
  • Like
  • 0
I'm just starting using Survey Force.  I don't see where I can add sub headers like they have in these directions:
https://www.stripathi.com/creating-questions-on-survey-with-survey-force-app/

Is there a way to make a multi page survey or sub headers to separate the questions into sections?
  • April 15, 2021
  • Like
  • 0
I have the following trigger and class, when an option is picked from a Case picklist called Macro, the corresponding case comment is to be added to the case.  I have tried various options I have found googling "test class for commentbody' but none seem to be covering the code in the last box.  The code works fine when updating a case, just needing the code coverage. 
trigger CW_DSS_CaseTriggerTSC50 on Case (after update) {
if(trigger.isafter && trigger.isupdate)
{
   CW_DSS_CaseTriggerHelper.CaseMethod1(Trigger.New,Trigger.oldMap);
}
  }
public class CW_DSS_CaseTriggerHelper{
           
           public static void CaseMethod1(List<Case> caseList, Map<Id,Case> oldmapValue){
           
if(CWcheckRecursive.runOnce())
    {
  
   List<caseComment> caseCommentList = new List<caseComment>();
    for (Case c: caseList)
    {
        
        caseComment cc = new caseComment();
        if(c.Macros__c == 'Application Support information'){
                cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);
                System.debug('********************************************************************'+ cc.commentbody);
               
        }
//insert caseCommentList;
            If(caseCommentList.Size() > 0){
            insert caseCommentList;
}}
           
           }
           
           
           }
}
/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class TestCW_DSS_CaseTrigger{
    
    
    
    static testMethod void CW_DSS_CaseTriggerTest(){
        Id caseRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Detect - Fatigue Management (DSS)').getRecordTypeId();
        ID accRecordTypeID = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Worksite').getRecordTypeId();
        Account a1 = new Account(Name='Carlin Test', RecordTypeID = accRecordTypeID, DSS_Account__c = true);
        insert a1;
      
        Case cs1 = new Case();
cs1.RecordTypeId = caseRecordTypeId;
cs1.Site_Dealer_Name_DSS__c = a1.Id;
cs1.OwnerId = UserInfo.getUserId();
cs1.CW_Type__c = 'Question';
cs1.Status = 'New';
cs1.Subject = 'This is my case';
cs1.Description = 'This is my description';
cs1.Incident_Start__c=Date.today();
cs1.Priority = 'Normal';
cs1.Subsystem_Type__c = 'Detect Analytics - API';
insert cs1;
    }

    static testMethod void testCaseMacros1() {
   
    
    Integer count = Limits.getLimitQueries() + 1;
    // set up case
    Id ortId = [SELECT Id, Name FROM RecordType WHERE Name='Detect - Fatigue Management (DSS)'].id;
    RecordType rtAcct = [select Id from RecordType WHERE Name = 'Worksite' and SobjectType = 'Account' limit 1];
    //create account
    Account a1 = new Account(Name='Carlin Test', RecordType = rtAcct, DSS_Account__c = true);
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];        
    System.runAs (thisUser){ 
        
        Case cse = new Case(RecordTypeId = ortId, Site_Dealer_Name_DSS__c = a1.Id, CW_Type__c = 'Incident', Subsystem_Type__c = 'Detect Analytics - API',
        Status = 'New', Subject = 'This is my case', Description = 'This is my description', Incident_Start__c=Date.today());
        Database.insert(cse);
        
        //cse.Macros__c = 'Application Support information';
       // Database.update(cse);
        
       test.startTest();
    cse.Macros__c = 'Application Support information';
    update cse;
    
    Case cs = [Select Id,Macros__c from case where Id=:cse.Id limit 1];
    system.debug('cs --> ' + cs);
    system.debug('cs --> ' + cs.Macros__c);
    system.assertEquals('Application Support information' , cs.Macros__c);
    
    List<caseComment> caseCommentList = [Select Id from caseComment];
    system.assert(caseCommentList.size()>0, 'caseComment not created');
    test.stopTest();
      
        
    
        
      }}}
 
cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);


 
  • March 18, 2021
  • Like
  • 0
I'm realizing I need to move some of the stuff in this trigger into an apex class.  This is a snippet of the trigger.  I have a picklist called Macros.  When a user choses a macro and clicks save on a case, the corresponding comment will be added to the case comment.  How can I accomplish this? 
trigger CW_DSS_CaseTrigger on Case (after update) {
  if(CWcheckRecursive.runOnce())
    {
  
   List<caseComment> caseCommentList = new List<caseComment>();
    for (Case c: Trigger.new)
    {
        
        caseComment cc = new caseComment();
        if(c.Macros__c == 'Application Support information'){
                cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);
                System.debug('********************************************************************'+ cc.commentbody);
               
        }

//insert caseCommentList;
            If(caseCommentList.Size() > 0){
            insert caseCommentList;
}}}

 
  • March 18, 2021
  • Like
  • 0
I'm trying to limit the usage of our pending statuses to only internal users.  I have added some code for validation on several statuses and added these in instead of 100s of validation rules.  
This is just a snippet.
//If the Status = Pending - NPI, fill in Product Category, Product Version and Defect Risk
                   if((objCase.CW_Current_User_s_Profile__c == 'CW Dealer Portal User' || objCase.CW_Current_User_s_Profile__c == 'CW Customer Portal Super User') && objCase.Status == 'Pending - NPI')
                   {
                       objCase.Status.addError('This status is restricted to Caterpillar. Choose another status.');
                   }else{ 
                   if(objCase.Status == 'Pending - NPI' && (string.isblank(objCase.Product_Category__c) || string.isblank(objCase.Product_Version__c) || string.isblank(objCase.NPI_Risk__c)))
                   {
                       objCase.addError('Fill in the Product Category, Product Version and Defect Risk for this case.');
                   }    }
The goal is to no allow Save if the customer or dealer user choose these statuses.  This works fine.  BUT if a case is already in one of these statuses and the customer or dealer go to edit the case, the validation rule also throws an error.  Without creating a new Support Process to weed out these statuses (tried that and it did not have favorable outcomes when it came to page layouts), how can I allows customer and dealer users to edit a case with this status, but not allow them to pick it from the Status list and Save. 


 
  • February 22, 2021
  • Like
  • 0
I have a trigger that adds a case comment depending on the field Macro option chosen.  Here's the trigger snippet 
trigger CW_DSS_CaseTrigger on Case (after update) {
  if(CWcheckRecursive.runOnce())
    {
    
   
   List<caseComment> caseCommentList = new List<caseComment>();
    for (Case c: Trigger.new)
    {
        
        caseComment cc = new caseComment();
        if(c.Macros__c == 'Application Support information'){
                cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);
               
        }
How do I get this covered in a test class?  Here's a snippet of my test class
private class TestCW_DSS_CaseTrigger{
    
    
    
    static testMethod void CW_DSS_CaseTriggerTest(){
        Id caseRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Detect - Fatigue Management (DSS)').getRecordTypeId();
        ID accRecordTypeID = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Worksite').getRecordTypeId();
        Account a1 = new Account(Name='Carlin Test', RecordTypeID = accRecordTypeID, DSS_Account__c = true);
        insert a1;
      
        Case cs1 = new Case();
cs1.RecordTypeId = caseRecordTypeId;
cs1.Site_Dealer_Name_DSS__c = a1.Id;
cs1.OwnerId = UserInfo.getUserId();
cs1.CW_Type__c = 'Question';
cs1.Status = 'New';
cs1.Subject = 'This is my case';
cs1.Description = 'This is my description';
cs1.Incident_Start__c=Date.today();
cs1.Priority = 'Normal';
cs1.Subsystem_Type__c = 'Detect Analytics - API';
insert cs1;
    }

    static testMethod void testCaseMacros1() {
    Id ortId = [SELECT Id, Name FROM RecordType WHERE Name='Detect - Fatigue Management (DSS)'].id;
    RecordType rtAcct = [select Id from RecordType WHERE Name = 'Worksite' and SobjectType = 'Account' limit 1];
    //create account
    Account a1 = new Account(Name='Carlin Test', RecordType = rtAcct, DSS_Account__c = true);
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];        
    test.startTest();
    System.runAs (thisUser) {
        
        Case cse = new Case(RecordTypeId = ortId, Site_Dealer_Name_DSS__c = a1.Id, CW_Type__c = 'Incident', Subsystem_Type__c = 'Detect Analytics - API',
        Status = 'New', Subject = 'This is my case', Description = 'This is my description', Incident_Start__c=Date.today());
        Database.insert(cse);
        cse.Macros__c = 'Application Support information';
        Database.update(cse);
        cse.Macros__c = '';
        Database.update(cse);
        
      test.stopTest();

    }}


 
  • January 06, 2021
  • Like
  • 0
I have the following VF Pages, depending on the subscription record type its related to.  The VF pages show the correct information.  When the record is saved and I click on it, the record type is the opposite of what it should be.  Do I need to created a separate class?
 
<apex:page standardController="Support_Subscription__c" extensions="MultiAd" id="thePage">

<script>
        sforce.connection.sessionId='{!GETSESSIONID()}';
        function init(){
           var result = sforce.connection.describeLayout('Support_Subscription__c'); //to do 
           console.log(result); //parse this object to find picklist values for each record type
        }
    </script>

    <body onload="init();">    
    </body>

<apex:form >

<apex:pageblock id="pb" >


    <apex:pageBlockButtons >

        <!--<apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>-->

        <apex:commandbutton value="Save" action="{!Save}"/>

    </apex:pageBlockButtons>
     <!--<apex:pageblock id="pb1">-->

   <apex:repeat value="{!wrappers}" var="e1" id="therepeat">
        <!--<apex:repeat value="{!lstInner}" var="e1" id="therepeat">-->
        

            <apex:panelGrid columns="10">

                <apex:panelGrid headerClass="Name">

                    <!--<apex:facet name="header">Del</apex:facet>

                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">

                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>

                    </apex:commandButton>-->

                </apex:panelGrid>
                <apex:inputField id="Record_Type" value="{!e1.asset.Support_Subscription_Record_Type__c}" onchange="setValue('Subscription Purchase Agreement Assets')" rendered="false"/>

                <apex:panelGrid >

                 <apex:facet name="header">Equipment/Registered Asset Licensed</apex:facet>

                    <apex:inputfield value="{!e1.asset.Equipment_Asset_Licensed__c}" style="width:200px" />

                </apex:panelGrid>

                <apex:panelGrid >

                    <apex:facet name="header">Serial Number</apex:facet>

                    <apex:inputfield value="{!e1.asset.Serial_Number__c}" style="width:95px"/>

                </apex:panelGrid>
         
                <apex:panelGrid >

                    <apex:facet name="header">Site Location</apex:facet>

                    <apex:inputfield value="{!e1.asset.Site_Location__c}" required="true"/>

               </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">MineStar Product</apex:facet>

                    <apex:inputfield value="{!e1.asset.MineStar_Product_Sub_Pur_Agr__c}" required="true" style="width:200px" />

                </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">Version</apex:facet>

                    <apex:inputfield value="{!e1.asset.Version__c}" style="width:95px" />  

                </apex:panelGrid>
                   <apex:panelGrid >

                    <apex:facet name="header">Machine Count</apex:facet>

                    <apex:inputfield value="{!e1.asset.Machine_Count__c}" required="true" style="width:95px" />  

                </apex:panelGrid>

            </apex:panelGrid>

        </apex:repeat>
<!--</apex:pageBlock>-->

</apex:pageblock>

</apex:form>

</apex:page>
 
<apex:page standardController="Support_Subscription__c" extensions="MultiAd" id="thePage">

<script>
        sforce.connection.sessionId='{!GETSESSIONID()}';
        function init(){
           var result = sforce.connection.describeLayout('Support_Subscription__c'); //to do 
           console.log(result); //parse this object to find picklist values for each record type
        }
    </script>

    <body onload="init();">    
    </body>

<apex:form >

<apex:pageblock id="pb" >


    <apex:pageBlockButtons >

        <!--<apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>-->

        <apex:commandbutton value="Save" action="{!Save}"/>

    </apex:pageBlockButtons>
     <!--<apex:pageblock id="pb1">-->

   <apex:repeat value="{!wrappers}" var="e1" id="therepeat">
        
            <apex:panelGrid columns="10">

                <apex:panelGrid headerClass="Name">

          </apex:panelGrid>         
<!------------------------------------------------------------------------------------------------------>

 <apex:inputField id="Record_Type" value="{!e1.asset.Support_Subscription_Record_Type__c}" onchange="setValue('Caterpillar Dealer Assets')" rendered="false"/>


     
                 <apex:panelGrid >

                     <apex:facet name="header">Equipment/Registered Asset Licensed</apex:facet>

                     <apex:inputfield value="{!e1.asset.Equipment_Asset_Licensed__c}" style="width:200px" />

                 </apex:panelGrid>

                <apex:panelGrid >

                    <apex:facet name="header">Serial Number</apex:facet>

                    <apex:inputfield value="{!e1.asset.Serial_Number__c}" style="width:95px"/>

                </apex:panelGrid>
         
                <apex:panelGrid >

                    <apex:facet name="header">Site Location</apex:facet>

                    <apex:inputfield value="{!e1.asset.Site_Location__c}" required="true"/>

               </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">MineStar Product</apex:facet>

                    <apex:inputfield value="{!e1.asset.MineStar_Product_Cat_Deal_Sub__c}" required="true" style="width:100px" />

                </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">Version</apex:facet>

                    <apex:inputfield value="{!e1.asset.Version__c}" style="width:100px"/>  

                </apex:panelGrid>
                <apex:panelGrid >

                    <apex:facet name="header">Machine Count</apex:facet>

                    <apex:inputfield value="{!e1.asset.Machine_Count__c}" required="true" style="width:100px"/>  

                </apex:panelGrid>


            </apex:panelGrid>
           

        </apex:repeat>
<!--</apex:pageBlock>-->

</apex:pageblock>

</apex:form>

</apex:page>
 
/*
Class/Method Name: MultiAd
Description: Created Subscription Assets related to Support Subscription
Author/Date: Staci Gilmore 5/27/2020
*/


public with sharing class MultiAd { 
private final Subscription_Assets__c ln; 
Public string ss;
public List<AccountWrapper> wrappers{get;set;}
private Integer nextIdent=0;

public MultiAd(ApexPages.StandardController controller) { 

ss = ApexPages.CurrentPage().getparameters().get('id');

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 




public List<Subscription_Assets__c> addlic {get; set;} 
  

public PageReference Save()
{
    List<Subscription_Assets__c> addlic=new List<Subscription_Assets__c>();
    Support_Subscription__c ssid = [select id, Name, RecordTypeId from Support_Subscription__c where id=:ss];
    for(AccountWrapper wrap:wrappers)
    {
       Subscription_Assets__c lic = wrap.asset;
       lic.Support_Subscription__c = ssid.id;
       addlic.add(lic);
    }
        
    insert addlic;
    

    PageReference pageRef = ApexPages.currentPage();
    pageRef.setRedirect(true);
    return pageRef;  
      
    
}

public class AccountWrapper
{
    public Subscription_Assets__c asset{get; private set;}
    public Integer ident{get; private set;}
    
    
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        asset=new Subscription_Assets__c();
            
    }
}         
}

 
  • December 23, 2020
  • Like
  • 0
I'm looking to create a case comment and update some of the case fields in a trigger.  This is what I have so far, but I get an error saying the record is read-only ( These lines c.Status = 'Pending'; c.Priority = 'Low'; c.CW_Type__c = 'Task';)
 
trigger CW_DSS_CaseTrigger on Case (after update) {
  if(CWcheckRecursive.runOnce())
    {
    
   List<Case> cwCasesUpdated = new List<Case>();
   List<caseComment> caseCommentList = new List<caseComment>();
    for (Case c: Trigger.new)
    {
        
        caseComment cc = new caseComment();
        if(c.Macros__c == 'Application Support information'){
                cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                cwCasesUpdated.add(c); 
                casecommentlist.add(cc);
               
        }
        if(c.Macros__c == 'Blackbox - Out of Scope'){
                cc.parentid = c.ID;
                cc.commentbody = 'Blackbox data requests can only be processed for incidents that occur involving driver fatigue, personal or property damage' +'\n' +
                'and injury related to fatigue or distraction and operator tampering.  The DSS is not to be used for disciplinary actions for mine safety violations.'+'\n' +
                'This eliminates sites wanting blackbox video for mine safety infractions, evidence of medical related injuries or diagnostic reasons.' +'\n' +
                 'This is to only be used if necessary to add evidence, clarify or discovery information about an incident or accident involving fatigue and/or distraction.';
                cc.ispublished = true;
                c.Status = 'Pending';
                c.Priority = 'Low';
                c.CW_Type__c = 'Task';
                casecommentlist.add(cc);
               
        }
       
    }
            insert caseCommentList;
            
          
    }
}

 
  • October 28, 2020
  • Like
  • 0
I have the following trigger to produce a canned response case comment when a option is picked from a picklist.  It works BUT if someone actually puts a case comment on a case after the picklist has been used, it errors:

Error:Apex trigger CW_DSS_CaseTrigger caused an unexpected exception, contact your administrator: CW_DSS_CaseTrigger: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CW_DSS_CaseTrigger: maximum trigger depth exceeded Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate: []: Trigger.CW_DSS_CaseTrigger: line 25, column 1


What is causing this?

 
trigger CW_DSS_CaseTrigger on Case (after update) {
    

   List<caseComment> caseCommentList = new List<caseComment>();
    for (Case c: Trigger.new)
    {
        
        caseComment cc = new caseComment();
        if(c.Macros__c == 'Application Support information'){
                cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);
               
        }

    }
            insert caseCommentList;
            
}

 
  • October 26, 2020
  • Like
  • 0
I need a report but everything I try isn't giving me what I need.

I have an object (Support Subscriptions).  I have a master-detail relationship with another custom object (Subscription Assets)
Master - Support Subscription
Detail - Subscription Asset

Support Subscription has a lookup to Accounts.  I have the related list on Accounts layout.

In my report I need to see what accounts have what assets.

In my custom report I used Accounts as the top object, then subscriptions using "A", then added assets using "B".

When I put the report and the assets are all -.  I know there are some assets so there should be something showing up in that column. Please help! 
  • October 22, 2020
  • Like
  • 0
I'm wondering if there is a way when a user fills out fields for a case, when they choose an option in a picklist, that canned text for that option would appear in the Description box for them to fill in (not upon save).  I've looked at Flows but I don't quite understand how to create from there.  I can't use apex cause Description is a field that HAS to be on the layout so I can't remove it and replace with an apex page. 
  • October 16, 2020
  • Like
  • 0
Wondering if this functionality is available.  I would like a user to be able to pick an option from a drop down field and some canned text pop in a text Description box, based on what option they choose.  
  • October 01, 2020
  • Like
  • 0
I have a field called Service Engineer.  When this field is filled in, a date/time stamp is filled in, SE Added.  When the Service Engineer field is blanked out another date/time stamp is filled in, SE Removed.  I then have a formula field that subtracts the Removed date from the Added date.  I need to accumulate this if the Service Engineer field is added and removed multiple times.  Is there a way to do this?
  • August 20, 2020
  • Like
  • 0
I'm trying to write a trigger to make sure certain fields are not empty based on the status that is chosen.  I have several different types of fields I'm trying to validate.  My code is below but it doesn't seem to be validating anything

Resolution_Detail__c = RTF
Workaround_ICA__c = RTF
Defect_Type_Multi__c = multipicklist
Declined_Reason__c= picklist
NPI_Numbertext__c = plain text
NPI_Tracking_Link__c = URL
CPI_Numbertext__c = plain text
CPI_Tracking_Link__c = URL
Change_Numbertext__c = plain text
CPI_Tracking_Link__c = URL





 
trigger CWStatusValidation on Case (before update, before insert)
{

              
        for (Case objCase : Trigger.new)
        {
           //If Status is any of the following and Resolution Detail is empty, prompt to fill in.
           if((objCase.Status == 'Closed - Cancelled' || objCase.Status == 'Closed - Unable to Reproduce' || objCase.Status == 'Closed - Duplicate'
           || objCase.Status == 'Recurring Incident') && objCase.Resolution_Detail__c == '')            
           {
                trigger.new[0].addError('Please fill in the Resolution Detail for this case.');
           }
              //If Status is any of the following and ICA is empty, prompt to fill in.
              if((objCase.Status == 'Pending - RCA' || objCase.Status == 'Pending - Customer Validation' 
              || objCase.Status == 'Pending - Dealer Validation' || objCase.Status == 'Pending - Evaluation') && objCase.Workaround_ICA__c == '')             
              {
                trigger.new[0].addError('Please fill in the Workaround / ICA for this case.');
              }
                    //If Status = Pending - CPI, fill in Resolution Details, CPI Number and CPI Tracking Link
                    if(objCase.Status == 'Pending - CPI' && objCase.CPI_Numbertext__c == ' ' && objCase.CPI_Tracking_Link__c == ' ' && objCase.Resolution_Detail__c == '' )            
                    {
                        trigger.new[0].addError('Please fill in the Resolution Details, CPI Number and CPI Tracking Link for this case.');
                    }
                         //If the Status = Closed - Declined, fill in Resolution Detail, Defect Type and Declined Reason.
                         if(objCase.Status == 'Closed - Declined' && objCase.Resolution_Detail__c == '' && objCase.Defect_Type_Multi__c == '' && objCase.Declined_Reason__c == '')
                         {
                           trigger.new[0].addError('Please fill in the Resolution Details, Defect Type and Declined Reason for this case.');
                         }
                            //If the Status = Pending - NPI, fill in Resolution Detail, NPI Number and NPI Tracking Link.
                            if(objCase.Status == 'Pending - NPI' && objCase.Resolution_Detail__c == '' && objCase.NPI_Numbertext__c == null && objCase.NPI_Tracking_Link__c == null)
                            {
                               trigger.new[0].addError('Please fill in the Resolution Details, NPI Number and NPI Tracking Link for this case.');
                            }
                                //If the Status = Pending - Change, fill in Resolution Detail, Change Number and Change Tracking Link.
                                if(objCase.Status == 'Pending - Change' && objCase.Resolution_Detail__c == '' && objCase.Change_Number__c == '' && objCase.Change_Tracking_Link__c == '')
                                {
                                   trigger.new[0].addError('Please fill in the Resolution Details, Change Number and Change Tracking Link for this case.');
                                }
                                    //If the Status is any of the following, fill in Resolution Detail and Defect Type.
                                    if((objCase.Status == 'Closed - Resolved' || objCase.Status == 'Closed - No Response') && objCase.Resolution_Detail__c == '' && objCase.Defect_Type_Multi__c == '' )
                                    {
                                       trigger.new[0].addError('Please fill in the Resolution Details and Defect Type for this case.');
                                    }
           
         }       
}
  • November 24, 2014
  • Like
  • 1
I'm wanting a way to get a count of useful solution articles.  Is there a way to do this sort of thing in apex or something.  I have no idea where to begin.  Any help would be awesome!
  • April 10, 2014
  • Like
  • 1
I have history tracking set for a custom field called Button Clicked on a custom object Change.  I have the field being updated through a Propose a Change button.  If a Dealer portal user clicks the buttton, the history gets updated and last modified gets updated.  If a Customer Portal User clicks the button the history doesn't get updated and the last modified date doesn't get updated.  I can't for the life of me see a difference between the 2 profiles except for the fact they are 2 different licenses.  Any ideas?
  • April 02, 2014
  • Like
  • 1
I'm building a sort of audit vf page for our products and was wondering if there is a way to make this circle(shown), then when a users clicks this circle once and it turns green, click twice and it turns yellow, click 3 times and it turns red.  
User-added image
  • December 16, 2022
  • Like
  • 0
I have the following code to move attachments from the inbound email message into Attachments - we are still in classic

I have 53% coverage right now.  Can't figure out how to get the last half of this code covered.
//test coverage in DSSEmailHandlerTest 
trigger CW_emailAttachmentReassigner on Attachment (before insert) {
        map<id, id> msgIdToParentId = new map<id, id>();
        Attachment[] reparents = new Attachment[]{};
        Schema.sObjectType email = emailmessage.getsobjecttype();
    

        for(Attachment a : trigger.new) {
            if(a.parentid != null){
                //see if the parent is an EmailMessage
                if(a.parentid.getsobjecttype() == EmailMessage.getsObjectType()) {



 //Test code from here down                 
 msgIdToParentId.put(a.parentid, null);
                    reparents.add(a);
                }
            }
        }
        
        if(!reparents.isEmpty()){
            for(EmailMessage em : [select id, parentID from EmailMessage where id =: msgIdToParentId.keyset()]){
                msgIdToParentId.put(em.id, em.parentId);
            }
        
            for(Attachment a : reparents) {
                a.parentId = msgIdToParentId.get(a.parentId);
            }
        }
        
    }
 
@isTest
private class DSSEmailHandlerTest
{
public static Blob createAttachmentBody(){
        String body = 'XXXXXXXXXXXXX';
        return Blob.valueof(body);
    }
    public static testMethod void testmyHandlerTest() 
    {
        Case c = new Case();
        insert c;
        
        Messaging.InboundEmail email = new Messaging.InboundEmail();
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        email.subject = 'ref';
        email.PlainTextBody = 'test body';
        
        // Add a Binary attachment to the email message!
        Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
        attachment.body = blob.valueOf('my attachment content');
        attachment.fileName = 'filename.txt';
        attachment.mimeTypeSubType = 'text/plain';
        email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment };
        
        DSSEmailHandler m = new DSSEmailHandler();
        m.handleInboundEmail(email, env);
     }
     
     
}

 
  • March 17, 2022
  • Like
  • 0
I'm trying to copy a case comment from emails and i want it to cut off before text A or before text B.  
CaseComment cc = new CaseComment(CommentBody=myCase.Last_email__c.substringbefore('Text A' OR 'Text B'),parentID=caseId);

What is the correct syntax?  This above obviously does not work
  • September 17, 2021
  • Like
  • 0
I have a field that when the radio button is yes, the field appears and needs to be filled in.  I have the title appearing, but the box to fill it in is not showing up.  What am I missing?  I'm just posting the snippet of the rerender and the field that needs to be filled in. User-added image
 
<apex:actionRegion >           
              <apex:selectRadio value="{!selectedOption}">
            
            <apex:selectOption itemValue="Yes" itemLabel="Yes" />
            <apex:selectOption itemValue="No" itemLabel="No" />
            <apex:actionSupport event="onchange" rerender="form" />
        </apex:selectRadio>
        </apex:actionRegion>
               
                            
                                                    
                <apex:panelGrid id="xxx" rendered="{!IF(selectedOption='Yes',True,False)}">
                    <apex:facet name="header">Date</apex:facet>
                    <apex:inputfield value="{!e1.asset.Date__c}" style="width:95px" required="true"/>
                </apex:panelGrid>

 
  • August 18, 2021
  • Like
  • 0
I have the following trigger and class, when an option is picked from a Case picklist called Macro, the corresponding case comment is to be added to the case.  I have tried various options I have found googling "test class for commentbody' but none seem to be covering the code in the last box.  The code works fine when updating a case, just needing the code coverage. 
trigger CW_DSS_CaseTriggerTSC50 on Case (after update) {
if(trigger.isafter && trigger.isupdate)
{
   CW_DSS_CaseTriggerHelper.CaseMethod1(Trigger.New,Trigger.oldMap);
}
  }
public class CW_DSS_CaseTriggerHelper{
           
           public static void CaseMethod1(List<Case> caseList, Map<Id,Case> oldmapValue){
           
if(CWcheckRecursive.runOnce())
    {
  
   List<caseComment> caseCommentList = new List<caseComment>();
    for (Case c: caseList)
    {
        
        caseComment cc = new caseComment();
        if(c.Macros__c == 'Application Support information'){
                cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);
                System.debug('********************************************************************'+ cc.commentbody);
               
        }
//insert caseCommentList;
            If(caseCommentList.Size() > 0){
            insert caseCommentList;
}}
           
           }
           
           
           }
}
/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class TestCW_DSS_CaseTrigger{
    
    
    
    static testMethod void CW_DSS_CaseTriggerTest(){
        Id caseRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Detect - Fatigue Management (DSS)').getRecordTypeId();
        ID accRecordTypeID = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Worksite').getRecordTypeId();
        Account a1 = new Account(Name='Carlin Test', RecordTypeID = accRecordTypeID, DSS_Account__c = true);
        insert a1;
      
        Case cs1 = new Case();
cs1.RecordTypeId = caseRecordTypeId;
cs1.Site_Dealer_Name_DSS__c = a1.Id;
cs1.OwnerId = UserInfo.getUserId();
cs1.CW_Type__c = 'Question';
cs1.Status = 'New';
cs1.Subject = 'This is my case';
cs1.Description = 'This is my description';
cs1.Incident_Start__c=Date.today();
cs1.Priority = 'Normal';
cs1.Subsystem_Type__c = 'Detect Analytics - API';
insert cs1;
    }

    static testMethod void testCaseMacros1() {
   
    
    Integer count = Limits.getLimitQueries() + 1;
    // set up case
    Id ortId = [SELECT Id, Name FROM RecordType WHERE Name='Detect - Fatigue Management (DSS)'].id;
    RecordType rtAcct = [select Id from RecordType WHERE Name = 'Worksite' and SobjectType = 'Account' limit 1];
    //create account
    Account a1 = new Account(Name='Carlin Test', RecordType = rtAcct, DSS_Account__c = true);
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];        
    System.runAs (thisUser){ 
        
        Case cse = new Case(RecordTypeId = ortId, Site_Dealer_Name_DSS__c = a1.Id, CW_Type__c = 'Incident', Subsystem_Type__c = 'Detect Analytics - API',
        Status = 'New', Subject = 'This is my case', Description = 'This is my description', Incident_Start__c=Date.today());
        Database.insert(cse);
        
        //cse.Macros__c = 'Application Support information';
       // Database.update(cse);
        
       test.startTest();
    cse.Macros__c = 'Application Support information';
    update cse;
    
    Case cs = [Select Id,Macros__c from case where Id=:cse.Id limit 1];
    system.debug('cs --> ' + cs);
    system.debug('cs --> ' + cs.Macros__c);
    system.assertEquals('Application Support information' , cs.Macros__c);
    
    List<caseComment> caseCommentList = [Select Id from caseComment];
    system.assert(caseCommentList.size()>0, 'caseComment not created');
    test.stopTest();
      
        
    
        
      }}}
 
cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);


 
  • March 18, 2021
  • Like
  • 0
I have a trigger that adds a case comment depending on the field Macro option chosen.  Here's the trigger snippet 
trigger CW_DSS_CaseTrigger on Case (after update) {
  if(CWcheckRecursive.runOnce())
    {
    
   
   List<caseComment> caseCommentList = new List<caseComment>();
    for (Case c: Trigger.new)
    {
        
        caseComment cc = new caseComment();
        if(c.Macros__c == 'Application Support information'){
                cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);
               
        }
How do I get this covered in a test class?  Here's a snippet of my test class
private class TestCW_DSS_CaseTrigger{
    
    
    
    static testMethod void CW_DSS_CaseTriggerTest(){
        Id caseRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Detect - Fatigue Management (DSS)').getRecordTypeId();
        ID accRecordTypeID = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Worksite').getRecordTypeId();
        Account a1 = new Account(Name='Carlin Test', RecordTypeID = accRecordTypeID, DSS_Account__c = true);
        insert a1;
      
        Case cs1 = new Case();
cs1.RecordTypeId = caseRecordTypeId;
cs1.Site_Dealer_Name_DSS__c = a1.Id;
cs1.OwnerId = UserInfo.getUserId();
cs1.CW_Type__c = 'Question';
cs1.Status = 'New';
cs1.Subject = 'This is my case';
cs1.Description = 'This is my description';
cs1.Incident_Start__c=Date.today();
cs1.Priority = 'Normal';
cs1.Subsystem_Type__c = 'Detect Analytics - API';
insert cs1;
    }

    static testMethod void testCaseMacros1() {
    Id ortId = [SELECT Id, Name FROM RecordType WHERE Name='Detect - Fatigue Management (DSS)'].id;
    RecordType rtAcct = [select Id from RecordType WHERE Name = 'Worksite' and SobjectType = 'Account' limit 1];
    //create account
    Account a1 = new Account(Name='Carlin Test', RecordType = rtAcct, DSS_Account__c = true);
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];        
    test.startTest();
    System.runAs (thisUser) {
        
        Case cse = new Case(RecordTypeId = ortId, Site_Dealer_Name_DSS__c = a1.Id, CW_Type__c = 'Incident', Subsystem_Type__c = 'Detect Analytics - API',
        Status = 'New', Subject = 'This is my case', Description = 'This is my description', Incident_Start__c=Date.today());
        Database.insert(cse);
        cse.Macros__c = 'Application Support information';
        Database.update(cse);
        cse.Macros__c = '';
        Database.update(cse);
        
      test.stopTest();

    }}


 
  • January 06, 2021
  • Like
  • 0
I'm wondering if there is a way when a user fills out fields for a case, when they choose an option in a picklist, that canned text for that option would appear in the Description box for them to fill in (not upon save).  I've looked at Flows but I don't quite understand how to create from there.  I can't use apex cause Description is a field that HAS to be on the layout so I can't remove it and replace with an apex page. 
  • October 16, 2020
  • Like
  • 0
I have a field called Service Engineer.  When this field is filled in, a date/time stamp is filled in, SE Added.  When the Service Engineer field is blanked out another date/time stamp is filled in, SE Removed.  I then have a formula field that subtracts the Removed date from the Added date.  I need to accumulate this if the Service Engineer field is added and removed multiple times.  Is there a way to do this?
  • August 20, 2020
  • Like
  • 0
I currently have a trigger that accumulates time spent in each of our status/substatus combos.  The time accumulates when the status/substatus is changed to the next status/substatus, but until that is changed, the time spent isn't actually current.  Is there a way to update this trigger so that when I say refresh the browser it will update the time for the current status/substatus instead of waiting till the status/substatus changes?

Here's a snippet of the code
trigger CaseStatusChangeTrigger on Case (before insert, before update) {
    DateTime currentTime = DateTime.now();

    for (Case c: trigger.new) {
        try { // Catch any exceptions that occur on a particular Case, for display to the user
            if (c.Current_Status_Start_Time__c == null) {
                // The ticket isn't already tracking time.
                // This either means it's new (trigger.isInsert case below),
                // or that it's a legacy ticket that existed before this trigger rolled out.
                // In either case, the time tracking fields need to be initialized;
                // set them all to decimal zero values.
                c.New_Hours__c = 0.0;
                c.Open_with_Dealer_Hours__c = 0.0;
                c.Open_with_Support_Advocates_Hours__c = 0.0;
                c.Open_with_Product_Specialists_Hours__c = 0.0;
                c.Awaiting_Customer_Response_Hours__c = 0.0;
                c.Awaiting_3rd_Party_Hours__c = 0.0;
                c.Pending_RCA_Hours__c = 0.0;
                c.Pending_CPI_Hours__c = 0.0;
                c.Pending_NPI_Hours__c = 0.0;
                c.Accumulated_Duration_Pending_Change__c = 0.0;
                //c.Pending_Evaluation_Hours__c = 0.0;
                c.Other_Status_Substatus_Hours__c = 0.0;
                c.Awaiting_Access_to_Machine_Hours__c = 0.0;
                c.Accumulated_Dur_Await_Tech_Avail_Hours__c = 0.0;//Added by Staci on 3/26/20 #00006009
                c.Open_with_CPI_Hours__c = 0.0;
                c.Pending_Customer_Validation_Hours__c = 0.0;
                c.Pending_Dealer_Validation_Hours__c = 0.0;
                c.Awaiting_Change_hours__c = 0.0;
                c.Pending_T3_hours__c = 0.0;
                c.RCA_Open_with_Customer_hours__c = 0.0;
                c.RCA_Open_with_Dealer_hours__c = 0.0;
                c.RCA_Open_with_PS_hours__c = 0.0;
                c.RCA_Open_with_SA_hours__c = 0.0;
                c.Pending_Reoccurrence_hours__c = 0.0;
                c.Accumulated_Duration_Open_with_Cat_Supp__c =0.0; //Added by Ramesh on 16-Jan2017 #00005171
                c.Accumulated_Duration_RCA_Open_w_CS__c=0.0;//Added by Ramesh on 16-Jan2017 #00005171
                c.Accumulated_Duration_CER_Release__c=0.0;//added by Staci 4/11/2017 ENT 2873
                c.Accumulated_Duration_CER_Prioritization__c=0.0;//added by Staci 4/11/2017 ENT 2873
                c.Accumulated_Duration_CER_Evaluation__c=0.0;//added by Staci 4/11/2017 ENT 2873
                c.Accumulated_Duration_CER_Cust_Funding__c=0.0;//added by Staci 4/11/2017 ENT 2873
                c.Accumulated_Duration_CER_Cancellation__c=0.0;//added by Staci 4/11/2017 ENT 2873
              //  c.Accumulated_Duration_Reviewed_hours__c = 0.0;
              //  c.Accumulated_Duration_Init_Review_hours__c = 0.0;
              //  c.Accumulated_Duration_Dev_in_Prog_hours__c = 0.0;
              //  c.Accumulated_Duration_Clarification_Hours__c = 0.0;
              //  c.Accumulated_Duration_User_Acc_Test_hours__c = 0.0;
              //  c.Accumulated_Duration_Funded_hours__c = 0.0;
            }
            if (trigger.isInsert) {
                // New case creation, just start the clock on the initial New status
                c.Current_Status_Start_Time__c = currentTime;
            }
            else {
                Case oldCase = trigger.oldMap.get(c.Id);
                if (oldCase == null) {          
                    // Internal error - Can't find the old case to log the time
                    // This "should never happen" (famous last words)
                    // Log the error if debugging
                    System.debug('Error in trigger CaseStatusChangeTrigger:  Can\'t find oldCase ' + c.Id + ' in map');
                    // Also show the error to the user
                    c.addError('Internal error in Apex trigger CaseStatusChangeTrigger:  Can\'t find old Case for status/substatus comparison.  Please contact a GIS Salesforce Administrator to report this error.');
                }
                else {
                    // Normal Case update, log the time to the appropriate Status and Substatus combination
                    // First save the new and old Status and Substatus values for comparison
                    String newStatus = c.Status;
                    String oldStatus = oldCase.Status;
                    String newSubstatus = c.Substatus__c;
                    String oldSubstatus = oldCase.Substatus__c;
                    Decimal currentStatusStartTime;
                    // Also calculate the elapsed hours in Status and Substatus for the Case
                    Decimal elapsedSeconds;
                    if (c.Current_Status_Start_Time__c == null) {
                        currentStatusStartTime = c.Incident_Start__c.getTime();
                    }
                    else {
                        currentStatusStartTime = c.Current_Status_Start_Time__c.getTime();
                    }
                    if (currentStatusStartTime == null) {
                        c.addError('Internal error in Apex trigger CaseStatusChangeTrigger:  No Incident Start Time recorded for legacy Case');
                        elapsedSeconds = 0.000000;
                    }
                    else {
                        elapsedSeconds = currentTime.getTime() - currentStatusStartTime;
                    }
                    Decimal elapsedHours = elapsedSeconds / (60 * 60 * 1000);
            
                    // If the Status and Substatus are both unchanged, do nothing
                    // Otherwise (either Status, Substatus or both have changed),
                    // log time if in a loggable Status and Substatus combination
                    if (c.Status != oldCase.Status || c.Substatus__c != oldCase.Substatus__c) {
                        // Status or Substatus has changed, log time into the appropriate variables
                        // First close out the current (old) Status and Substatus combination
                        // by logging time into the appropriate bucket for that combination
                        if (oldCase.Status == 'New') {
                            // New Status:  Regardless of Substatus, log time into the New bucket
                            if(c.New_Hours__c != Null) {
                              c.New_Hours__c += elapsedHours;
                            }
                            else {
                                c.New_Hours__c = 0.0;
                                c.New_Hours__c += elapsedHours;
                            }
                        }
                        else if (oldCase.Status == 'In Progress') {
                            // In Progress Status:  5 trackable Substatuses with buckets for time
                            if (oldCase.Substatus__c == 'Open with Dealer') {
                                // Log into the "Open with Dealer Hours" bucket
                                if(c.Open_with_Dealer_Hours__c != Null) {
                                  c.Open_with_Dealer_Hours__c += elapsedHours;
                                }
                                else {
                                    c.Open_with_Dealer_Hours__c = 0.0;
                                    c.Open_with_Dealer_Hours__c += elapsedHours;
                                }
                            }
                            else if (oldCase.Substatus__c == 'Open with Support Advocates') {
                                // Log into the "Open with Support Advocates" bucket
                                if(c.Open_with_Support_Advocates_Hours__c != Null) {
                                  c.Open_with_Support_Advocates_Hours__c += elapsedHours;
                                }
                                else {
                                    c.Open_with_Support_Advocates_Hours__c = 0.0;
                                    c.Open_with_Support_Advocates_Hours__c += elapsedHours;
                                }
                            }

--------LOTS OF DUPLICATED CODE FOR EACH STATUS/SUBSTATUS----------
catch (Exception e) {
            // General exception in the trigger
            // This "should never happen" (famous last words)
            // Show the exception message to the user
            // Log the error if debugging
            System.debug('Exception in trigger CaseStatusChangeTrigger: ' + e.getMessage() + ' for Case "' + c.CaseNumber + '" (ID = ' + c.Id + ')');
            // Also show the error to the user
            c.addError('Internal error in trigger CaseStatusChangeTrigger: ' + e.getMessage() + ' for Case "' + c.CaseNumber + '" (ID = ' + c.Id + ')');
        }
    }
}

 
  • July 29, 2020
  • Like
  • 0
I have some code I found on here to create "Add Row" functionality.  Everything seems to work except the Save button.  Its not creating the new records.  

What should happen is on a Subscription record, I have an embedded apex page to add Subscription Assets (which is a related list on the Subscription record).  I want to be able to add multiple rows of the Subscription Assets and save them to the related list on the Subscription record.  What happens is when I click save, it refreshes, blanks out the fields in the embedded apex page and doesn't save any of the Subscription Asset records anywhere.  It's been awhile since I've done any coding and I'm a bit rusty. 

Apex Page
<apex:page standardController="Support_Subscription__c" extensions="MultiAdd" id="thePage">

<apex:form >

<apex:pageblock id="pb" >


    <apex:pageBlockButtons >

        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>

        <apex:commandbutton value="Save" action="{!Save}"/>

    </apex:pageBlockButtons>
     <apex:pageblock id="pb1">

   
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
        

            <apex:panelGrid columns="10">

                <apex:panelGrid headerClass="Name">

                    <apex:facet name="header">Del</apex:facet>

                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">

                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>

                    </apex:commandButton>

                </apex:panelGrid>

                <apex:panelGrid >

                 <apex:facet name="header">Equipment/Asset Licensed</apex:facet>

                    <apex:inputfield value="{!e1.asset.Equipment_Asset_Licensed__c}"/>

                </apex:panelGrid>

                <apex:panelGrid >

                    <apex:facet name="header">Serial Number</apex:facet>

                    <apex:inputfield value="{!e1.asset.Serial_Number__c}"/>

                </apex:panelGrid>
         
                <apex:panelGrid >

                    <apex:facet name="header">Site Location</apex:facet>

                    <apex:inputfield value="{!e1.asset.Site_Location__c}"/>

               </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">MineStar Product</apex:facet>

                    <apex:inputfield value="{!e1.asset.MineStar_Product__c}" style="width:200px"/>

                </apex:panelGrid>
                
                <apex:panelGrid >

                    <apex:facet name="header">Version</apex:facet>

                    <apex:inputfield value="{!e1.asset.Version__c}"/>

                </apex:panelGrid>

            </apex:panelGrid>

        </apex:repeat>
</apex:pageBlock>

</apex:pageblock>

</apex:form>

</apex:page>

Class
public class MultiAdd {

    

    //will hold the Subscription Asset records to be saved

    public List<Subscription_Assets__c>lstAsset = new List<Subscription_Assets__c>();

    //list of the inner class

    public List<innerClass> lstInner

    {   get;set;    }

    //will indicate the row to be deleted

    public String selectedRowIndex

    {get;set;} 
    
    Public Support_Subscription__c ss
        {get;set;}

    //no. of rows added/records in the inner class list

    public Integer count = 1;
    

    //{get;set;}

    ////save the records by adding the elements in the inner class list to lstAsset,return to the same page

    public PageReference Save()

    {
         
        PageReference pr = new PageReference('/apex/CW_Support_Subscription');
 for(Subscription_Assets__c sa : lstAsset)
 {
        for(Integer j = 0;j<lstInner.size();j++)

        {
           

            sa.Support_Subscription__c  = ss.Name;
            lstAsset.add(lstInner[j].asset);
        } 
        }
        insert lstAsset;
        
        pr.setRedirect(True);

        return pr;

    }

    //add one more row

    public void Add()

    {  

        count = count+1;

        addMore();     

    }

    /*Begin addMore*/

    public void addMore()

    {

        //call to the iner class constructor

        innerClass objInnerClass = new innerClass(count);

        //add the record to the inner class list

        lstInner.add(objInnerClass);   

        system.debug('lstInner---->'+lstInner);           

    }/* end addMore*/

    /* begin delete */

    public void Del()

    {

        system.debug('selected row index---->'+selectedRowIndex);

        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);

        count = count - 1;

    }/*End del*/

    /*Constructor*/

    public MultiAdd(ApexPages.StandardController ctlr)

    {

        lstInner = new List<innerClass>();

        addMore();

        selectedRowIndex = '0';

    }/*End Constructor*/

    /*Inner Class*/

    public class innerClass

    {      

        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */

        public String recCount

        {get;set;}

        public Subscription_Assets__c asset

        {get;set;}
        
        

        /*Inner Class Constructor*/

        public innerClass(Integer intCount)

        {

            recCount = String.valueOf(intCount);       
           
            /*create a new account*/

            asset = new Subscription_Assets__c();
            
            
            

        }/*End Inner class Constructor*/   

    }/*End inner Class*/

}/*End Class*/
User-added image
​​​​​​​
  • May 07, 2020
  • Like
  • 0
I'm making an escalate case button for our customers to use.  I need the funtionality to assign the case to a generic support queue if a checkbox is true, if not I need it to assign the case to the corresponding partner queue, which are set in the case assignment rules.  Is there a way to invoke the assignment rules in the javascript button? 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 


if('{!Case.CW_Advance_Support_Needed__c}' == true) 
{ 
caseObj.OwnerId = '00G30000001oUSL'; 
caseObj.Status = 'In Progress'; 

}else{ 


caseObj.CW_Advance_Support_Needed__c='True'; 
caseObj.Escalated_Date_Time__c=new Date().toJSON(); 

} 

if('{!Case.Incident_First_Response__c}'=='') 
{ 
caseObj.Incident_First_Response__c=new Date().toJSON(); 
} 

var result = sforce.connection.update([caseObj]); 
window.location.href=window.location.href;
  • September 18, 2018
  • Like
  • 0
I have a test class that is 68% covered.  I have 2 lines throughout that I cannot get covered.  Can anyone help me get them covered?
Its the 2 lines after the else statement.  
 
if (oldCase.Substatus__c == 'Open with Cat Support') {
                                // Log into the "Open with Cat Support" bucket
                                if(c.Accumulated_Duration_Open_with_Cat_Supp__c != Null) {
                                  c.Accumulated_Duration_Open_with_Cat_Supp__c += elapsedHours;
                                }
                                else {
                                    c.Accumulated_Duration_Open_with_Cat_Supp__c = 0.0;
                                    c.Accumulated_Duration_Open_with_Cat_Supp__c += elapsedHours;
                                }
                            }

 
  • April 17, 2017
  • Like
  • 0