• Antoine Leleu
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
Hi all,

I developed a Http Callout Class. I can cover this code at 100% with a test method using MockHttpResponseGenerator.
Then i developed a custom controller calling this Http Callout Class and i'm trying to develop the test metohd for this controller.

If i run my test, i obtain this error "Methods defined as TestMethod do not support Web service callouts, test skipped". 
So, i read in the forum that i had to add a condition on my http call out call like this "if (!System.Test.isRunningTest())" to execute my test.

But in this case, my Call Out class is not covered at 100% cause the lines between the condtion can be executed.

Has someone already encountered this problem ? Is there any solution or workaround for this ?

Thanks,

Antoine

 
Hello all,

I need help to have 100% code coverage on trigger. 
Only 57% are covered by the test and the 3 last lines are not.
This is my trigger (to prevent the closure of case if the completion of case milsetones are not filled)

trigger MilestoneCompletionDateRequiredToClose on Case (before update) {
   
     for (Case c : trigger.new) {
        if(c.Status == 'Closed'){
             List<CaseMilestone> CaseMls = [select Id, completionDate from CaseMilestone
                       where caseId = :c.Id ];
            if(CaseMls.isEmpty() == false){          
                for (CaseMilestone cm : CaseMls){
                    if(cm.CompletionDate == null)
                    c.addError('The completion Date of Case Milestone(s) must be filled to close the case');   
                }  
            }
        }
     }
}

and this my test :

"@isTest
private class MilestoneCompletionDateRequiredTest {

    static testMethod void CloseCaseTest() {
        // TO DO: implement unit test
   
  Account acc = new account(name = 'TestCoverage', Zone__c = 'EMEA');
        insert acc;
    Contact con = new contact(accountId = acc.id, lastname='Coverage', firstname='Test');
        insert con;
        Entitlement ent = new entitlement(name = 'CoverageEntitlement', AccountId = acc.Id);
        insert ent;
  Case cseA = new case(accountId = acc.id, contactId = con.id, subject = 'TestCoverage1', EntitlementId = ent.Id);
        insert cseA;
       
        List<CaseMilestone> CaseMls = [select Id, completionDate from CaseMilestone
                            where caseId = :cseA.Id ];
        
      cseA.status = 'Closed';
        try{
   update cseA;
  }catch(Exception e){
         if(CaseMls.isEmpty() == false){          
             for (CaseMilestone cm : CaseMls){
              if(cm.completionDate == null){
      system.assertEquals(e.getMessage(), 'The completion Date of Case Milestone(s) must be filled to close the case');
     }
             }
         }
       }  
   }  
}"

thanks for your help
Hi all,

I would like create a trigger when a case comment is add to a Case. I know it's easy to implement taht for the public comment.
But i need to trigger an action each time a Case comment is add, does'nt matter if it's public or private.

Thanks,
Antoine

Hello,

 

I try to code a trigger to send data to an external API.

I would like to use external JAR file with several class to connect to my application.

 

Is to possible to add external JAR files in apex trigger ?

 

Thanks,

Antoine

Hi,

 

i'm trying to code an client app to update cases.

 I use the update() call to update a custom field. But when i run my application, i have this error : 

 

"ERROR updating record: Unable to create/update fields: CaseNumber"

 

However i don't set the case number in my case. Is it possible to update cases with the update() call ?

This my code :

 

private static void updateCases() {
   
System.out.println("Querying for the cases...");
   
try {
      
// query for the cases      
QueryResult queryResults = connection.query("SELECT Id, CaseNumber " +
      "FROM Case WHERE RT_id__c = '4622'");
     if (queryResults.getSize() > 0) {
     //Define records
     Case[] records = new Case[queryResults.getSize()];
     
     for (int i=0;i<queryResults.getRecords().length;i++) {
     // cast the SObject to a strongly-typed Case
     Case c = (Case)queryResults.getRecords()[i];
     System.out.println("Id: " + c.getId() + " - CaseNumber: "+c.getCaseNumber());
         
     System.out.println("Update cases...");
         
     //update case
     c.setFramework_Found_in_txt__c("ixE-4.18.0");
     records[i] = c;
     }
         
     SaveResult[] saveResults = connection.update(records);
         // check the returned results for any errors
      for (int i=0; i<saveResults.length; i++) {
      if (saveResults[i].isSuccess()) {
      System.out.println(i+". Successfully updated record - Id: " + saveResults[i].getId());
      } else {
      Error[] errors = saveResults[i].getErrors();
      for (int j=0; j<errors.length; j++) {
      System.out.println("ERROR updating record: " + errors[j].getMessage());
      }
      }    
      }
       
     }    
 
     
} catch (Exception e) {
     e.printStackTrace();
}   
 
 
Hello all,

I need help to have 100% code coverage on trigger. 
Only 57% are covered by the test and the 3 last lines are not.
This is my trigger (to prevent the closure of case if the completion of case milsetones are not filled)

trigger MilestoneCompletionDateRequiredToClose on Case (before update) {
   
     for (Case c : trigger.new) {
        if(c.Status == 'Closed'){
             List<CaseMilestone> CaseMls = [select Id, completionDate from CaseMilestone
                       where caseId = :c.Id ];
            if(CaseMls.isEmpty() == false){          
                for (CaseMilestone cm : CaseMls){
                    if(cm.CompletionDate == null)
                    c.addError('The completion Date of Case Milestone(s) must be filled to close the case');   
                }  
            }
        }
     }
}

and this my test :

"@isTest
private class MilestoneCompletionDateRequiredTest {

    static testMethod void CloseCaseTest() {
        // TO DO: implement unit test
   
  Account acc = new account(name = 'TestCoverage', Zone__c = 'EMEA');
        insert acc;
    Contact con = new contact(accountId = acc.id, lastname='Coverage', firstname='Test');
        insert con;
        Entitlement ent = new entitlement(name = 'CoverageEntitlement', AccountId = acc.Id);
        insert ent;
  Case cseA = new case(accountId = acc.id, contactId = con.id, subject = 'TestCoverage1', EntitlementId = ent.Id);
        insert cseA;
       
        List<CaseMilestone> CaseMls = [select Id, completionDate from CaseMilestone
                            where caseId = :cseA.Id ];
        
      cseA.status = 'Closed';
        try{
   update cseA;
  }catch(Exception e){
         if(CaseMls.isEmpty() == false){          
             for (CaseMilestone cm : CaseMls){
              if(cm.completionDate == null){
      system.assertEquals(e.getMessage(), 'The completion Date of Case Milestone(s) must be filled to close the case');
     }
             }
         }
       }  
   }  
}"

thanks for your help
Hi all,

I would like create a trigger when a case comment is add to a Case. I know it's easy to implement taht for the public comment.
But i need to trigger an action each time a Case comment is add, does'nt matter if it's public or private.

Thanks,
Antoine

Hi,

 

i'm trying to code an client app to update cases.

 I use the update() call to update a custom field. But when i run my application, i have this error : 

 

"ERROR updating record: Unable to create/update fields: CaseNumber"

 

However i don't set the case number in my case. Is it possible to update cases with the update() call ?

This my code :

 

private static void updateCases() {
   
System.out.println("Querying for the cases...");
   
try {
      
// query for the cases      
QueryResult queryResults = connection.query("SELECT Id, CaseNumber " +
      "FROM Case WHERE RT_id__c = '4622'");
     if (queryResults.getSize() > 0) {
     //Define records
     Case[] records = new Case[queryResults.getSize()];
     
     for (int i=0;i<queryResults.getRecords().length;i++) {
     // cast the SObject to a strongly-typed Case
     Case c = (Case)queryResults.getRecords()[i];
     System.out.println("Id: " + c.getId() + " - CaseNumber: "+c.getCaseNumber());
         
     System.out.println("Update cases...");
         
     //update case
     c.setFramework_Found_in_txt__c("ixE-4.18.0");
     records[i] = c;
     }
         
     SaveResult[] saveResults = connection.update(records);
         // check the returned results for any errors
      for (int i=0; i<saveResults.length; i++) {
      if (saveResults[i].isSuccess()) {
      System.out.println(i+". Successfully updated record - Id: " + saveResults[i].getId());
      } else {
      Error[] errors = saveResults[i].getErrors();
      for (int j=0; j<errors.length; j++) {
      System.out.println("ERROR updating record: " + errors[j].getMessage());
      }
      }    
      }
       
     }    
 
     
} catch (Exception e) {
     e.printStackTrace();
}