function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EvertonSzekeresEvertonSzekeres 

How to identify which test class is bringing 74%

Hi,

I can't deploy anything in my organization because I always get 74%.
I read in some topics that maybe I have a test class that have 0% coverage or some other issue.

I executed all my test class and the first test class I've encountered an issue  is bringing me 100% coverage in 2 of my triggers:

@istest(seealldata=true)
public class AtualizarProduto_adquirido_deleteSA_test{
    static testmethod void unittest(){
        
        Account acc=new Account();
        acc.FirstName = 'Tste';
        acc.LastName = 'Teste';
        acc.ID_do_formando__c = 'CP7_0000_000001';
        acc.Turma__c = 'a06U0000006GuHc';
        acc.Nome_do_produto_adquirido__c = 'SUPER ÁLBUM';
        acc.Data_da_venda_SA__c = Date.today();
        acc.Situacao__c = 'VENDA APROVADA';
        acc.pesquisa_de_mercado__c = '1 - Pesquisa Satisfação B2';
        acc.antecipado__c = null;
        insert acc;
      
        Asset a=new Asset();       
         a.name = 'SUPER ÁLBUM';
         a.Price = 1000;
         a.Parcelas__c = 10;
         a.data_do_contrato__c = date.today();
         a.accountId = acc.id;
         a.quantity = 0;
        insert a;
        
         a.Status = 'Cancelado';
        update a;
            
        acc.Nome_do_produto_adquirido__c = null;
        acc.Data_da_venda_SA__c = null;
        update acc;
        }
 }

When I execute I get this error:
Methods defined as TestMethod do not support Web service callouts, test skipped
EnreecoEnreeco
This is because in the test methods you cannot make any http/soap callout.
I think you have some callout that is triggered by a trigger on Account or Asset object.
YOu may have to handle the future call see http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm for SOAP testing or http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm for REST/HTTP calls.
EvertonSzekeresEvertonSzekeres
It is the first time that I tried to create a future call.

I don't know exactly what I a did wrong.

public class CanceladoSA{
    @future
    public static void updateAccountProdutoDataSA() {
        
        Account acc = [SELECT Id, Nome_do_produto_adquirido__c, Data_da_venda_SA__c FROM Account WHERE FirstName = 'Tste' AND LastName = 'Teste' AND ID_do_formando__c = 'CP7_0000_000001' AND Nome_do_produto_adquirido__c = 'SUPER ÁLBUM' AND Data_da_venda_SA__c != null AND Situacao__c = 'VENDA APROVADA' AND antecipado__c = null AND recordtypeid = '012U00000000vYx'];
        Asset a = [SELECT Id, accountid, Status FROM Asset WHERE Name='SUPER ÁLBUM' AND Quantity = 0];
 
            a.Status = 'Cancelado';
            a.accountid = acc.id;
        update a;
        
            acc.Nome_do_produto_adquirido__c = null;
            acc.Data_da_venda_SA__c = null;
            acc.id = a.accountid;
        update acc;
    }
}
public class MixedDMLFuture {
    public static void useFutureMethod() {
        
        Asset a = new Asset(Quantity = 0, Name='SUPER ÁLBUM');
        insert a;
  
        CanceladoSA.updateAccountProdutoDataSA();        
    }
}
@isTest
private class AtualizarProduto_adquirido_deleteSA_test {
    @isTest static void test1() {
        Account thisAccount = [SELECT Id FROM Account WHERE Nome_do_produto_adquirido__c = null AND Data_da_venda_SA__c = null];

            Test.startTest();        
            MixedDMLFuture.useFutureMethod();
            Test.stopTest();
        
        Asset[] a = [SELECT Id from Asset where Status = 'Cancelado' AND name = 'SUPER ÁLBUM'];
        System.assertEquals(1, a.size());

        Account[] ac = [SELECT Id from Account WHERE Nome_do_produto_adquirido__c = 'SUPER ÁLBUM' AND Data_da_venda_SA__c != null AND recordtypeid = '012U00000000vYx' AND Id = : a[0].accountid];
        System.assertEquals(1, ac.size());
     
    }
}

Trigger:
trigger AtualizarNome_do_Produto_adquirido_deleteSA on Asset (after update) {

Set <id> ids = new Set <id> ();
    for (Asset a: trigger.new) {
            if (a.name == 'SUPER ÁLBUM' && a.status == 'Cancelado') {
       ids.add(a.accountId);
            }
        }
for (Account acc : [select ID, recordtypeid, Nome_do_produto_adquirido__c, Data_da_venda_SA__c from Account WHERE id IN: ids]){
    if (acc.recordtypeid == '012U00000000vYx'){
        acc.Nome_do_produto_adquirido__c = null;
        acc.Data_da_venda_SA__c = null;
        update acc;
    }   
}           
    }