• Guilherme Brito 8
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hello, is there a way to define which email alert will be fired or dynamically set the From? I have 30+ email2cases and I would like to set a specific 'From' address to the user that receives the email. I was wondering if the easiest way would be to configure a specific email alert to all email2cases and then use, maybe SOQL, to define the one that will be fired. Thnx
I wrote a controller and a test class that runs just fine in my QA but when I try to deploy it an error occours
"System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, The time trigger value calculated by the Apex class "CalculateSLAMilestone" must be a positive integer .: []
Stack Trace: Class.faleConoscoVFController.duplicateCasoSon: line 47, column 1 Class.faleConoscoVFController.rejectSolution: line 32, column 1 Class.faleConoscoVFControllerTest.test: line 19, column 1"
 
public class faleConoscoVFController {
    public static case css {get; set;}
    public static string motive{get;set;}
    public static boolean disableReopening{get;set;}
    public static boolean caseReopened{get;set;}
    public static string caseID = ApexPages.currentPage().getParameters().get('caseID');
    public static datetime data{get;set;}
    
    public static void onLoad(){
        css = [SELECT id, CaseNumber, Subject, CreatedDate, Description, Status, Data_de_Fechamento__c
               FROM Case 
               WHERE id =:caseID];
        
        faleConoscoVFController.disableReopening();
    }
    
    public static void disableReopening(){
        if(css.Data_de_Fechamento__c < (Date.Today() - 7)){
            disableReopening = true;
        }
    }
    
    public static void rejectSolution(){
        case css2 = [SELECT id, CaseNumber, Subject, CreatedDate, Description, Status, Data_de_Fechamento__c, Data_Prevista_Fechamento__c
                     FROM Case 
                     WHERE id =:caseID];
        
        css2.Status = 'Novo';
        css2.Caso_Reaberto_por_E_mail__c = true;
        update css2;
        caseReopened = true;
        faleConoscoVFController.duplicateCasoFilho();
        data = css2.Data_Prevista_Fechamento__c;
    }
    
    public static void duplicateCasoFilho(){
        case newCase = new case();
        case oldCase = [SELECT ID, Subject, Description, Area_Resolucao__c FROM Case WHERE ParentID =:caseID
                        ORDER BY CreatedDate DESC LIMIT 1];
        
        newCase.Subject = oldCase.Subject;
        newCase.Description = motive;
        newCase.Area_Resolucao__c = oldCase.Area_Resolucao__c;
        newCase.Status = 'Em Tratamento';
        newCase.RecordTypeId = '0121V000001IhK9QAK';
        newCase.ParentId = caseID;
        insert newCase;
    }
}
 
@isTest(SeeAllData=true)
public class faleConoscoVFControllerTest {
    @isTest(SeeAllData=true)
    static void test(){
        Test.startTest();
        case caso = new case();
        insert caso;
        
        case casoFilho = new case();
        casoFilho.ParentId = caso.Id;
        insert casoFilho;
        
        system.debug('Caso: ' + caso.id);
        system.debug('Caso Filho: ' + casoFilho.id);
        
        faleConoscoVFController.data = date.today();
        faleConoscoVFController.caseID = caso.Id;
        faleConoscoVFController.disableReopening = false;
        faleConoscoVFController.onLoad();       
        faleConoscoVFController.rejectSolution();
        Test.stopTest();
    }
}

Could anyone help me with this, please?
I wrote a controller and a test class that runs just fine in my QA but when I try to deploy it an error occours
"System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, The time trigger value calculated by the Apex class "CalculateSLAMilestone" must be a positive integer .: []
Stack Trace: Class.faleConoscoVFController.duplicateCasoSon: line 47, column 1 Class.faleConoscoVFController.rejectSolution: line 32, column 1 Class.faleConoscoVFControllerTest.test: line 19, column 1"
 
public class faleConoscoVFController {
    public static case css {get; set;}
    public static string motive{get;set;}
    public static boolean disableReopening{get;set;}
    public static boolean caseReopened{get;set;}
    public static string caseID = ApexPages.currentPage().getParameters().get('caseID');
    public static datetime data{get;set;}
    
    public static void onLoad(){
        css = [SELECT id, CaseNumber, Subject, CreatedDate, Description, Status, Data_de_Fechamento__c
               FROM Case 
               WHERE id =:caseID];
        
        faleConoscoVFController.disableReopening();
    }
    
    public static void disableReopening(){
        if(css.Data_de_Fechamento__c < (Date.Today() - 7)){
            disableReopening = true;
        }
    }
    
    public static void rejectSolution(){
        case css2 = [SELECT id, CaseNumber, Subject, CreatedDate, Description, Status, Data_de_Fechamento__c, Data_Prevista_Fechamento__c
                     FROM Case 
                     WHERE id =:caseID];
        
        css2.Status = 'Novo';
        css2.Caso_Reaberto_por_E_mail__c = true;
        update css2;
        caseReopened = true;
        faleConoscoVFController.duplicateCasoFilho();
        data = css2.Data_Prevista_Fechamento__c;
    }
    
    public static void duplicateCasoFilho(){
        case newCase = new case();
        case oldCase = [SELECT ID, Subject, Description, Area_Resolucao__c FROM Case WHERE ParentID =:caseID
                        ORDER BY CreatedDate DESC LIMIT 1];
        
        newCase.Subject = oldCase.Subject;
        newCase.Description = motive;
        newCase.Area_Resolucao__c = oldCase.Area_Resolucao__c;
        newCase.Status = 'Em Tratamento';
        newCase.RecordTypeId = '0121V000001IhK9QAK';
        newCase.ParentId = caseID;
        insert newCase;
    }
}
 
@isTest(SeeAllData=true)
public class faleConoscoVFControllerTest {
    @isTest(SeeAllData=true)
    static void test(){
        Test.startTest();
        case caso = new case();
        insert caso;
        
        case casoFilho = new case();
        casoFilho.ParentId = caso.Id;
        insert casoFilho;
        
        system.debug('Caso: ' + caso.id);
        system.debug('Caso Filho: ' + casoFilho.id);
        
        faleConoscoVFController.data = date.today();
        faleConoscoVFController.caseID = caso.Id;
        faleConoscoVFController.disableReopening = false;
        faleConoscoVFController.onLoad();       
        faleConoscoVFController.rejectSolution();
        Test.stopTest();
    }
}

Could anyone help me with this, please?