• Clement Debrueres-Bartoli
  • NEWBIE
  • 30 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 8
    Replies
Hey Salesforce friends :),

I am having an issue with these 2 classes. In Sandbox I get 85% code coverage, but when I deploy it goes to 30%. There must be something wrong but I can't manage to find out the bug. Any idea on how I could improve it? Thank you very much.
 
global class CaseUpdateReminder1 implements Database.Batchable<Sobject> ,System.Schedulable{

    global Database.QueryLocator start(Database.BatchableContext bc) 
    
    {return Database.getQueryLocator([SELECT Id FROM Case WHERE Eligible_Case__c='Yes' AND Reminder_1_Period__c = TRUE]);
    }

    global void execute(Database.BatchableContext bc, List<Case> scope)
    
    {for (Case Cases : scope) 
            
            {
                Cases.Priority = 'High';
                Cases.Internal_Action_Needed__c = 'Send Email';
                Cases.Reminder_1_Field_Update_Done__c = TRUE;
                Cases.OwnerId = '00G3W000001LjOcUAK'          
                
            }
        update scope;
    }    

    global void finish(Database.BatchableContext bc){}    

    global void execute(SchedulableContext SC){
    Database.executeBatch(new CaseUpdateReminder1(), 50);
    }
    }
in the code above, "Reminder_1_Period__c" is a formula field, TRUE if CreatedDate=TODAY, which is why I put the CreatedDate in the Test.



And its Test class:
@isTest 

public class CaseUpdateReminder1_Test 
{
    static testMethod void testMethod1() 
    {
        List<Case> lstCase = new List<Case>();

            Case cas = new Case();
            
    cas.OwnerId = '0053W000001LxTEQA0';
    cas.RecordTypeId = '0123W000000L3JSQA0';
    cas.Priority = 'Medium';
    case.CreatedDate = date.parse('10/02/2022'), 
    cas.Reminder_1_Field_Update_Done__c = FALSE;
    cas.UID__c = 'Test12345';
      
            lstCase.add(cas);
        
        
        insert lstCase;
        
        Test.startTest();

            CaseUpdateReminder1 obj = new CaseUpdateReminder1();
            DataBase.executeBatch(obj); 
            
        Test.stopTest();
    }
}
Thank you very much and all the best :)
 
Hey glorious fellas,

I want to add automatically the message "thank you for contacting us" at the end of each of the chat conversations, within the chat conversation itself.

I can also make this text as a custom field value, for example Text_to_display__c.

What would be the best way to achieve this?

I am using Embedded Services for Chat.

Thank you very much and stay safe !
Hi Salesforce friends,

I am still a beginner with Apex class and I have a requirement to create a VF page showing all the open cases of the Acount.

My VF page is
<apex:page standardController="Case" extensions="ShowCustomersOpenCases">
<apex:form > 
<apex:pageBlock >
<apex:pageBlockTable value="{!CA}" var="C" columnsWidth="1%,1%,1%" >                                                     
                <apex:column headerValue="Case Number" >
                <apex:commandLink value="{!C.CaseNumber}" action="/{!C.Id}" target="_blank" />
                </apex:column>                
                <apex:column headerValue="Status" value="{!C.Status}" />
                <apex:column headerValue="Created Date" value="{!C.CreatedDate}" />       
</apex:pageBlockTable>               
</apex:pageBlock>
</apex:form>
</apex:page>
My Apex Controller is
 
public with sharing class ShowCustomersOpenCases {

    public List<Case> CA { get; private set; }

    public ShowCustomersOpenCases(ApexPages.StandardController controller) {
        controller.addFields(new List<String>{ 'AccountId' });
        Case currentCase = (Case)controller.getRecord();
        CA = [Select Id, CaseNumber, CreatedDate, Status, Subject, ContactId FROM Case Where Status <> 'Closed' AND AccountId = :currentCase.AccountId and Id != :currentCase.Id Order by CreatedDate DESC Limit 100];
      }
}

But I dont manage to create a proper Test Class, after a lot of attempts.

Any good soul who could help me with that test Class?

Thank you very much
​​​​​​​
 
Hi Salesforce fellas,

I have a requirement to create a VF page to display a list of all Cases of the Account, where Status is not "Closed.

My VF page code is
<apex:page controller="CustomersOpenCases">
    <apex:form >
        <apex:pageBlock title="Open Cases" id="cases_list">
            <apex:repeat value="{!newCases}" var="case" id="case">
                <p><apex:outputLink value="/{!case.Id}">{!case.CaseNumber}</apex:outputLink> &nbsp;&nbsp;
                <apex:outputLink value="/{!case.Id}">{!case.Status}</apex:outputLink></p>
            </apex:repeat>
        </apex:pageBlock>
    </apex:form>
</apex:page>

My Apex controller Class is:
 
public class CustomersOpenCases {

    public List<Case> getNewCases() {
        List<Case> results = Database.query(
            'SELECT Id, CaseNumber, Status ' +
            'FROM Case ' +
            'WHERE Status = \'New\' OR Status = \'Reopen\' OR Status = \'Waiting\' '
        );
   
    return results;
    }

}

But after a lot of attempts I dont manage to create the Test Class for it.

Any idea on how I should create the corresponding Test Class ?

Thank you very much,

Clement 
Hi Salesforce fellas,

I am still a beginner with Case Triggers and I would like to create an Apex Trigger that would update the children cases everytime the parent case is updated (any update on any field of the Parent).
* To make the parent-child relationship, I just use the standard method and enter the Parent Case number in "Parent Case" field of the Child Case.

The Children Cases would have their following fields updated with the value in the Parent Case:
Status, ClosedDate, Category, SubCategory, SubCategory2, Category_Bank, SubCategory_Bank

I made this Case Trigger  but it just does not work, and it is only when Parent Case ' Status' field is updated to "Closed"
 
trigger updateChildCases on Case (after update) {
  

        List<Case> childrenToUpdate = new List<Case>();
        Set<Id> parentIds = new Set<Id>();
        for(Case p:trigger.new) {
        
            if(p.IsClosed == TRUE) {
                parentIds.add(p.Id);
            }
        }
        if(parentIds.size() > 0) {
            for(Case ch : [SELECT Id, 
            Parent.Status,
            Parent.ClosedDate,
            
            Parent.Category__c,
            Parent.SubCategory_2__c, 
            Parent.SubCategory__c,
            
            Parent.Category_Bank__c,
            Parent.SubCategory_Bank__c  
            
            FROM Case WHERE Parent.Id IN :parentIds
            AND Parent.Status <> NULL
            AND PArent.ClosedDate <> NULL
            
            AND Parent.Category__c <> NULL
            AND Parent.SubCategory__c <> NULL
            AND Parent.SubCategory_2__c <> NULL
            
            AND Parent.Category_Bank__c <> NULL
            AND Parent.SubCategory_Bank__c <> NULL
            ]) {
 
                ch.Status = ch.Parent.Status;                 ch.ClosedDate = ch.Parent.ClosedDate;                 ch.Category__c = ch.Parent.Category__c;                 ch.SubCategory__c = ch.Parent.SubCategory__c;                 ch.SubCategory_2__c = ch.Parent.SubCategory_2__c;                ch.Category_Bank__c = ch.Parent.Category_Bank__c;                ch.SubCategory_Bank__c = ch.Parent.SubCategory_Bank__c;
 
                childrenToUpdate.add(ch);
            } 
Update childrenToUpdate;
            }
        }
my test class is probably incomplete:
@isTest
private class UpdateChildCases_Test {
 
  static testMethod void Test(){
            
    Case curCase = new Case(Status = 'Closed',
    Category__c ='Registration',
    SubCategory__c = 'Open/Reopen Account',
    SubCategory_2__c = 'Create Profile',
    Category_Bank__c = '1',
    SubCategory_Bank__c = '2' );
    insert curCase;
    
    Case curCase2 = new Case(Status='New',ParentId=curCase.Id);
    insert curCase2;

       Test.StartTest(); 
 
    Test.StopTest();
  }
}
(sorry if the code burns your eyes )

I get some code coverage and no error when I save the trigger and the test class, but then when I go back to my cases and try to close a Parent Case it just does not update the Child Case.

Any good soul who could help me with that please?

Thank you very much :)
Hello fellas,

For my spam emails, I currently have this process for Cases:

-if Custom field "Mark as Spam" is ticked by User, then move the Case to "Spam" queue and mark the Status as "Closed"

This PB works well, no problem. All my Spams go to this queue, in Closed status.

However I would also like to integrate the deletion of those Cases in the process: Case should be deleted 4 hours after they have been moved and closed. (I dont want to delete immediately, I need the Case to stay a few hours in the queue)

There are several options, but which one would be the simplest and cleanest to achieve this regular deletion of spam cases?

Thank you very much
Hello folks,

When a chat is requested by a customer, this customer is assigned to a Live Chat Visitor name, which attributes an ID number to customer's device. Basically, same device would always have the same ID and it cannot really fail.

In order to avoid that a customer hits the chat button twice, is it possible to setup a logic that would say "if Live Chat Visitor XXX already has an active ongoing chat, this same Visitor cannot hit the chat button again to open a second chat or Chat cannot be initiated if Live Chat Visitor has an ongoing chat"

Thank you for your help
Hello,
When a Chat Transcript is created, a Live Chat Transcript Events log is created and attached to the Chat Transcript.
Is there any way to delete these Transcripts Events, ideally 10 days after the Chat has happened?
Is there a way to create a scheduled job deleting the Transcript Events automatically ?

The reason is I dont need these Transcript Events after 10 days, and they consume serious storage space.

Thank you,
Hey Salesforce friends :),

I am having an issue with these 2 classes. In Sandbox I get 85% code coverage, but when I deploy it goes to 30%. There must be something wrong but I can't manage to find out the bug. Any idea on how I could improve it? Thank you very much.
 
global class CaseUpdateReminder1 implements Database.Batchable<Sobject> ,System.Schedulable{

    global Database.QueryLocator start(Database.BatchableContext bc) 
    
    {return Database.getQueryLocator([SELECT Id FROM Case WHERE Eligible_Case__c='Yes' AND Reminder_1_Period__c = TRUE]);
    }

    global void execute(Database.BatchableContext bc, List<Case> scope)
    
    {for (Case Cases : scope) 
            
            {
                Cases.Priority = 'High';
                Cases.Internal_Action_Needed__c = 'Send Email';
                Cases.Reminder_1_Field_Update_Done__c = TRUE;
                Cases.OwnerId = '00G3W000001LjOcUAK'          
                
            }
        update scope;
    }    

    global void finish(Database.BatchableContext bc){}    

    global void execute(SchedulableContext SC){
    Database.executeBatch(new CaseUpdateReminder1(), 50);
    }
    }
in the code above, "Reminder_1_Period__c" is a formula field, TRUE if CreatedDate=TODAY, which is why I put the CreatedDate in the Test.



And its Test class:
@isTest 

public class CaseUpdateReminder1_Test 
{
    static testMethod void testMethod1() 
    {
        List<Case> lstCase = new List<Case>();

            Case cas = new Case();
            
    cas.OwnerId = '0053W000001LxTEQA0';
    cas.RecordTypeId = '0123W000000L3JSQA0';
    cas.Priority = 'Medium';
    case.CreatedDate = date.parse('10/02/2022'), 
    cas.Reminder_1_Field_Update_Done__c = FALSE;
    cas.UID__c = 'Test12345';
      
            lstCase.add(cas);
        
        
        insert lstCase;
        
        Test.startTest();

            CaseUpdateReminder1 obj = new CaseUpdateReminder1();
            DataBase.executeBatch(obj); 
            
        Test.stopTest();
    }
}
Thank you very much and all the best :)
 
Hi Salesforce friends,

I am still a beginner with Apex class and I have a requirement to create a VF page showing all the open cases of the Acount.

My VF page is
<apex:page standardController="Case" extensions="ShowCustomersOpenCases">
<apex:form > 
<apex:pageBlock >
<apex:pageBlockTable value="{!CA}" var="C" columnsWidth="1%,1%,1%" >                                                     
                <apex:column headerValue="Case Number" >
                <apex:commandLink value="{!C.CaseNumber}" action="/{!C.Id}" target="_blank" />
                </apex:column>                
                <apex:column headerValue="Status" value="{!C.Status}" />
                <apex:column headerValue="Created Date" value="{!C.CreatedDate}" />       
</apex:pageBlockTable>               
</apex:pageBlock>
</apex:form>
</apex:page>
My Apex Controller is
 
public with sharing class ShowCustomersOpenCases {

    public List<Case> CA { get; private set; }

    public ShowCustomersOpenCases(ApexPages.StandardController controller) {
        controller.addFields(new List<String>{ 'AccountId' });
        Case currentCase = (Case)controller.getRecord();
        CA = [Select Id, CaseNumber, CreatedDate, Status, Subject, ContactId FROM Case Where Status <> 'Closed' AND AccountId = :currentCase.AccountId and Id != :currentCase.Id Order by CreatedDate DESC Limit 100];
      }
}

But I dont manage to create a proper Test Class, after a lot of attempts.

Any good soul who could help me with that test Class?

Thank you very much
​​​​​​​
 
Hi Salesforce fellas,

I have a requirement to create a VF page to display a list of all Cases of the Account, where Status is not "Closed.

My VF page code is
<apex:page controller="CustomersOpenCases">
    <apex:form >
        <apex:pageBlock title="Open Cases" id="cases_list">
            <apex:repeat value="{!newCases}" var="case" id="case">
                <p><apex:outputLink value="/{!case.Id}">{!case.CaseNumber}</apex:outputLink> &nbsp;&nbsp;
                <apex:outputLink value="/{!case.Id}">{!case.Status}</apex:outputLink></p>
            </apex:repeat>
        </apex:pageBlock>
    </apex:form>
</apex:page>

My Apex controller Class is:
 
public class CustomersOpenCases {

    public List<Case> getNewCases() {
        List<Case> results = Database.query(
            'SELECT Id, CaseNumber, Status ' +
            'FROM Case ' +
            'WHERE Status = \'New\' OR Status = \'Reopen\' OR Status = \'Waiting\' '
        );
   
    return results;
    }

}

But after a lot of attempts I dont manage to create the Test Class for it.

Any idea on how I should create the corresponding Test Class ?

Thank you very much,

Clement 
Hi Salesforce fellas,

I am still a beginner with Case Triggers and I would like to create an Apex Trigger that would update the children cases everytime the parent case is updated (any update on any field of the Parent).
* To make the parent-child relationship, I just use the standard method and enter the Parent Case number in "Parent Case" field of the Child Case.

The Children Cases would have their following fields updated with the value in the Parent Case:
Status, ClosedDate, Category, SubCategory, SubCategory2, Category_Bank, SubCategory_Bank

I made this Case Trigger  but it just does not work, and it is only when Parent Case ' Status' field is updated to "Closed"
 
trigger updateChildCases on Case (after update) {
  

        List<Case> childrenToUpdate = new List<Case>();
        Set<Id> parentIds = new Set<Id>();
        for(Case p:trigger.new) {
        
            if(p.IsClosed == TRUE) {
                parentIds.add(p.Id);
            }
        }
        if(parentIds.size() > 0) {
            for(Case ch : [SELECT Id, 
            Parent.Status,
            Parent.ClosedDate,
            
            Parent.Category__c,
            Parent.SubCategory_2__c, 
            Parent.SubCategory__c,
            
            Parent.Category_Bank__c,
            Parent.SubCategory_Bank__c  
            
            FROM Case WHERE Parent.Id IN :parentIds
            AND Parent.Status <> NULL
            AND PArent.ClosedDate <> NULL
            
            AND Parent.Category__c <> NULL
            AND Parent.SubCategory__c <> NULL
            AND Parent.SubCategory_2__c <> NULL
            
            AND Parent.Category_Bank__c <> NULL
            AND Parent.SubCategory_Bank__c <> NULL
            ]) {
 
                ch.Status = ch.Parent.Status;                 ch.ClosedDate = ch.Parent.ClosedDate;                 ch.Category__c = ch.Parent.Category__c;                 ch.SubCategory__c = ch.Parent.SubCategory__c;                 ch.SubCategory_2__c = ch.Parent.SubCategory_2__c;                ch.Category_Bank__c = ch.Parent.Category_Bank__c;                ch.SubCategory_Bank__c = ch.Parent.SubCategory_Bank__c;
 
                childrenToUpdate.add(ch);
            } 
Update childrenToUpdate;
            }
        }
my test class is probably incomplete:
@isTest
private class UpdateChildCases_Test {
 
  static testMethod void Test(){
            
    Case curCase = new Case(Status = 'Closed',
    Category__c ='Registration',
    SubCategory__c = 'Open/Reopen Account',
    SubCategory_2__c = 'Create Profile',
    Category_Bank__c = '1',
    SubCategory_Bank__c = '2' );
    insert curCase;
    
    Case curCase2 = new Case(Status='New',ParentId=curCase.Id);
    insert curCase2;

       Test.StartTest(); 
 
    Test.StopTest();
  }
}
(sorry if the code burns your eyes )

I get some code coverage and no error when I save the trigger and the test class, but then when I go back to my cases and try to close a Parent Case it just does not update the Child Case.

Any good soul who could help me with that please?

Thank you very much :)
Hello fellas,

For my spam emails, I currently have this process for Cases:

-if Custom field "Mark as Spam" is ticked by User, then move the Case to "Spam" queue and mark the Status as "Closed"

This PB works well, no problem. All my Spams go to this queue, in Closed status.

However I would also like to integrate the deletion of those Cases in the process: Case should be deleted 4 hours after they have been moved and closed. (I dont want to delete immediately, I need the Case to stay a few hours in the queue)

There are several options, but which one would be the simplest and cleanest to achieve this regular deletion of spam cases?

Thank you very much