0
@AuraEnabled
    public static List<RL_Service_Detail__c> deleteContact(String conid) {
        if(conid != null){
            RL_Service_Detail__c delContact = [Select Id from RL_Service_Detail__c where id=:conid];
            delete delContact;
        }

        return [SELECT Id, RL_Service__c, RL_Client__r.Id, RL_Client__r.Name, RL_Category__c, RL_Sub_category__c, RL_Unit__c, RL_Billing_type__c,
                 RL_Is_Deleted__c FROM RL_Service_Detail__c ];
}
@isTest static void testDeleteContact() {
    List<RL_Service_Detail__c> before = [SELECT Id FROM RL_Service_Detail__c];

    Test.startTest();
    Boolean result = Service.DeleteContact(before.get(0).Id);
    Test.stopTest();

    List<RL_Service_Detail__c> after = [SELECT Id FROM RL_Service_Detail__c];

    System.assert(result);
    System.assertEquals(1, before.size());
    System.assertEquals(0, after.size());
}
1
  • 2
    Seems pretty straightforward. Your DeleteContact() method returns a List<RL_Service_Detail__c>, not a boolean. There isn't a standard way to convert between those two types. You should remove that assignment (and the related system.assert()), or edit your question to explain what you're trying to do. Like I've said on multiple occasions, you need to provide details.
    – Derek F
    Commented Oct 9, 2020 at 11:04

2 Answers 2

1

The problem is you are trying to store the returned value of the method deleteContact which is of type List<RL_Service_Detail__c> into a boolean variable named result.

You need to change the line

Boolean result = Service.DeleteContact(before.get(0).Id);

to

List<RL_Service_Detail__c> result = Service.DeleteContact(before.get(0).Id);
0

From your method, you are returning List<RL_Service_Detail__c>, but in your test method, you are assigning it to Boolean. See the below code.

  @isTest static void testDeleteContact() {
        List<RL_Service_Detail__c> before = [SELECT Id FROM RL_Service_Detail__c];

        Test.startTest();
        //Boolean result = Service.DeleteContact(before.get(0).Id);
        List<RL_Service_Detail__c> rlList = Service.DeleteContact(before.get(0).Id);
        Test.stopTest();

        List<RL_Service_Detail__c> after = [SELECT Id FROM RL_Service_Detail__c];

        //System.assert(result);
        System.assertEquals(1, before.size());
        System.assertEquals(0, after.size());
    }
4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .