• Valentina Doda 7
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies

Hi there,

I a trying to start a test class for this apex class but I find it difficult to construct the test class. Can sb please help?

The apex class is: 

public with sharing class OCSRecuperaCampagneC5SASInvoker { public class OCSRecuperaCampagneC5SASInvokerRequest extends APIRequest { public String serviceId = 'recuperaCampagneC5SAS'; public Map<String, String> companyType = new Map<String, String>{'value' => 'COMPASS'}; public String authorization; public Map<String, String> recuperaCampagneC5SASRequest; public OCSRecuperaCampagneC5SASInvokerRequest(String codFiscale) { this.recuperaCampagneC5SASRequest = new Map<String, String>{'codFiscale' => codFiscale, 'codCliente' => ''}; } } public class OCSRecuperaCampagneC5SASInvokerResponse extends APIResponse { public Integer resultCode; public String resultMessage; public Map<String, String> recuperaCampagneC5SASResponse; } public static Boolean isValidSASFiscalCode(String fiscalCode, Date dueDate) { Boolean isValid = false; OCSRecuperaCampagneC5SASInvokerRequest request = new OCSRecuperaCampagneC5SASInvokerRequest(fiscalCode); OCSRecuperaCampagneC5SASInvokerResponse response = (OCSRecuperaCampagneC5SASInvokerResponse)ApiUtils.callApi('ocs.recuperaCampagneC5SAS', request, OCSRecuperaCampagneC5SASInvokerResponse.class); System.debug('---> OCSRecuperaCampagneC5SASInvokerResponse: ' + response); if(response.resultMessage == 'OK' && response.recuperaCampagneC5SASResponse != null && String.isNotBlank(response.recuperaCampagneC5SASResponse.get('codFiscale')) && response.recuperaCampagneC5SASResponse.get('codFiscale').trim() == fiscalCode && String.isNotBlank(response.recuperaCampagneC5SASResponse.get('dataEstrazione'))) { Date dataEstrazione = Date.valueOf(response.recuperaCampagneC5SASResponse.get('dataEstrazione')); isValid = dataEstrazione <= dueDate && dataEstrazione.daysBetween(dueDate) <= 180; } return isValid; } public static Boolean isValidSASFiscalCode(String fiscalCode) { return isValidSASFiscalCode(fiscalCode, System.today()); } public static String getOpportunitySourceCode(String fiscalCode, Date dueDate) { return isValidSASFiscalCode(fiscalCode, dueDate) ? 'L02' : 'L00'; } public static String getOpportunitySourceCode(String fiscalCode) { return getOpportunitySourceCode(fiscalCode, System.today()); } public class FlowInputVariables { @InvocableVariable(Required = true) public String fiscalCode ; @InvocableVariable(Required = true) public Date dueDate; } public class FlowOutputVariables { @InvocableVariable public Boolean isValidSASFiscalCode; @InvocableVariable public String opportunitySourceCode; } @InvocableMethod(Callout=true Label='Check Codice Fiscale SAS' Description='Restituisce true se il codice fiscale è presente su SAS e la relativa data di estrazione è ancora valida.') public static List<FlowOutputVariables> isValidSASFiscalCode(List<FlowInputVariables> flowInputVariablesList) { List<FlowOutputVariables> flowOutputVariablesList = new List<FlowOutputVariables>(); for(FlowInputVariables flowInputVariables: flowInputVariablesList) { FlowOutputVariables flowOutputVariables = new FlowOutputVariables(); flowOutputVariables.isValidSASFiscalCode = isValidSASFiscalCode(flowInputVariables.fiscalCode, flowInputVariables.dueDate); flowOutputVariables.opportunitySourceCode = flowOutputVariables.isValidSASFiscalCode ? 'L02' : 'L00'; flowOutputVariablesList.add(flowOutputVariables); } return flowOutputVariablesList; } }

Thnx,
Valentina

Hello everyone, 
I am working on a test class in apex and this is the class:
global class Flow_Dynamic_EmailAlerts {
    //@AuraEnabled public String emailTemplateName;
    //@AuraEnabled public List<User> recipients;    @InvocableMethod(label='Send request alert' description='Given a list of users it sends an email with email template to the users')
    public static void innerMethodInvocable(List<Flow_Dynamic_EmailAlerts_Request> request){
        EmailTemplate emailTemplate = [
            SELECT Id, Subject,Description, HtmlValue,DeveloperName,Body
            FROM EmailTemplate
            WHERE DeveloperName =: request[0].emailTemplateName
        ];        Set<String> userIdsSet = new Set<String>(request[0].recipients);
        List<User> users = [SELECT Id, Email FROM User WHERE Id IN:new List<String>(userIdsSet)];
        List<String> addresses = new List<String>();        for(User recipient : users) addresses.add(recipient.Email);        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setTargetObjectId(UserInfo.getUserId());
        message.setSenderDisplayName('Salesforce Alert');
        //message.setReplyTo(recipient.Email);
        message.setUseSignature(false);
        message.setBccSender(false);
        message.setSaveAsActivity(false);        //Get templete id for set the templete.        message.setTemplateID(emailTemplate.Id);
        //message.setWhatId(account.Id); //merge fields ???
        message.toAddresses = addresses;        Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};        Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);        if (results[0].success) System.debug('The email was sent successfully.');
        else System.debug('The email failed to send: ' +results[0].errors[0].message);
    }    global class Flow_Dynamic_EmailAlerts_Request {
        @InvocableVariable(required=true)
        global String emailTemplateName;        @InvocableVariable(required=true)
        global List<String> recipients;
    }
}

I am trying to test the class but I cannot understand how to start. All the methotds I've try doesn't work. 

Can sb please see it and explain somehow how shoult I start?
Thanks very much