I have to call a class apex from to FLOW.
This is my class Apex:
global class relojesCobranzaAutomatizado { @InvocableMethod(label='Get ID cuenta factura' description='asigna el reloj cobranza de acuerdo al segmento de la cuenta factura.')
global class relojesCobranzaAutomatizado {
@InvocableMethod(label='Get ID cuenta factura' description='asigna el reloj cobranza de acuerdo al segmento de la cuenta factura.')
public static final String ERROR = '1';
public static final String SUCCESS = '0';
global class Respuesta{
webService String resultDescription{get;set;}
webService String result;
global Respuesta(String resultDescription, String result){
this.resultDescription = resultDescription;
this.result = result;
}
}
// METHOD 1.
public static String metodoOficial(List<ID> ids){
String segmentos;
String ctasFact;
String rfc;
String razonSocial;
String relojUno = '1';
String relojDos = '2';
List<CuentaFactura__c> ctaFact = [SELECT IdCuentaBRM__c, Nuevo_Segmento__c, RFC__c, Name FROM CuentaFactura__c WHERE Id IN: ids];
for(CuentaFactura__c cf : ctaFact){
razonSocial = cf.Name;
rfc = cf.RFC__c;
ctasFact = cf.IdCuentaBRM__c;
segmentos = cf.Nuevo_Segmento__c;
}
if(segmentos.contains('I')){
serviceRelojes(ctasFact, relojDos);
}else if(segmentos.contains('II')){
serviceRelojes(ctasFact, relojDos);
}else if(segmentos.contains('III')){
serviceRelojes(ctasFact, relojDos);
}else if(segmentos.contains('IV')){
serviceRelojes(ctasFact, relojUno);
}else if(segmentos.contains('') || segmentos.contains(null)){
serviceRelojes(ctasFact, relojDos);
}
return null;
}
// METHOD 2.
public static Map<String, Object> serviceRelojes(String cuentaFact, String collectorId){
Map<String, Object> datos = new Map<String, Object>();
datos.put('msj', 'OK');
// WEB SERVICE.
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(EndPoint__c.getValues('ChangeWatch').URL__c);
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setHeader('Accept', 'application/json');
// SET THE BODY AS A JSON OBJECT.
String name = 'Saleas';
String login = '"Login" : {"user" : "2550017","password" : "M450$","ip" : "0.0.0.0"}';
String datosCuenta = '"BRM" : {"account" : "' + cuentaFact + '", "PROGRAM_NAME" : " ' + name + '","COLLECTOR_ID" : "' + collectorId + '"}';
request.setBody('{' + login + ',' + datosCuenta + '}');
HttpResponse response;
if (Test.isRunningTest()){
Test.setMock(HttpCalloutMock.class, new DASH_DashboardRelojCobranzaAct_Mock());
response = http.send(request);
} else{
response = http.send(request);
}
// Parse the JSON response
if (response.getStatusCode() == 200){
datos = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
}else{
datos.put('msj', 'error');
datos.put('response', response);
}
return datos;
}
}
This is my FLOW: