You need to sign in to do that
Don't have an account?
Leticia Monteiro Freitas 4
Uncaught Action failed [system is not defined]
Hello, I trying to create a Lightining Component that search a Account according the code.
But I get this error:
Uncaught Action failed: c:CEC_SearchAccountComponent$controller$handleClick [system is not defined]
Following the codes:
cmp--
<aura:component controller="CEC_SearchAccount" implements="force:appHostable">
<aura:attribute name="acctList" type="Account[]" />
<ui:inputText aura:id="searchText" label="Insira o CPF ou CNPJ" required="TRUE"/>
<lightning:button variant="brand" label="Buscar" onclick="{!c.handleClick}"/>
<aura:iteration items="{!v.acctList}" var="a">
<p>{!a.Name},{!a.Type}</p>
</aura:iteration>
</aura:component>
controller ---
({
/* Dentro da ação de clicar no botão, a classe controladora aponta para a função validKey*/
handleClick : function(component, event, helper) {
system.debug("Entrou na função HandleClick");
var input_text = component.get("v.searchText")
var action = component.get("c.validKey");
action.setParams({text:cmp.get("input_text")});
action.setCallback(this,function(response)
{
var state = response.getState();x
if(component.isValid() && STATE==Sucess){
component.set("v.acctList",response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Class--
public class CEC_SearchAccount{
public static List<Account> getfoundAccount(String[] Key, String documentType)
{
List<Account> Conta = [Select ID, Name, DocumentType__c,DocumentNumber__c,FormattedDocument__c,BillingAddress from Account
where DocumentNumber__c =:Key AND DocumentType__c =:documentType];
return Conta;
}
public static void getvalidCPF(String[] CPF)
{
/* Cálcula se o cpf é valido através do cálculo dos digitos validadores.*/
integer value;
integer coeff = 10, sum, rest;
String dig10,dig11;
//Calcula o primeiro digito validador do CPF
for(integer i=0; i<9;i++)
{
value = Integer.valueOf(cpf[i])* coeff;
coeff--;
sum = sum + value ;
}
rest = 11 - math.mod(sum,11);
if((rest == 10) || (rest == 11))
{
dig10 = '0';
}else{
dig10 = String.valueOf(rest);
}
sum = 0;
coeff = 11;
value = 0;
for(integer i=0;i<10;i++)
{
value = Integer.valueOf(cpf[i])*coeff;
coeff--;
sum = sum + value;
}
rest = 11 - math.mod(sum,11);
if((rest == 10) || (rest==11))
{
dig11 = '0';
}else{
dig11=String.valueOf(rest);
}
// Validate if the calculus match
if((dig11 == cpf[11]) && (dig10 == cpf[10]))
{
String documentType = 'CPF';
getfoundAccount(CPF,documentType);
}else{
system.debug('CNPJ iNVÁLIDO');
}
}
public static void getvalidCNPJ(String[]CNPJ)
{
integer value;
integer coeff=12,sum,rest;
String dig13,dig14;
for(integer i = 0; i < 12;i++)
{
value = Integer.valueOf(CNPJ[i]) * coeff;
coeff--;
sum = sum + value;
}
rest =Math.mod(sum,11);
if((rest == 0) || (rest == 1))
{
dig13 = '0';
}else{
dig13 = String.valueOf(11 - rest);
}
// Calculando o segundo digito verificador do CNPJ
rest=0;
coeff=13;
for(integer i = 0;i<13;i++)
{
value = Integer.valueOf(CNPJ[i]) * coeff;
coeff--;
sum = sum + value;
}
rest = math.mod(sum,11);
if((rest == 0) || (rest == 1))
{
dig14 = '0';
}else{
dig14 = String.valueOf(11 - rest);
}
if((CNPJ[13] == dig13) && (CNPJ[14] == dig14))
{
String documentType ='CNPJ';
getfoundAccount(CNPJ, documentType);
}else{
//
}
}
@AuraEnabled
Public static void getvalidKey(String[] text)
{
/*Após ler a string de caracteres, o sistema chama a função de cpf ou cnpj conformo o tamanho da string */
system.debug('Chegou na função da classe');
if(text.size() == 11)
{
getvalidCPF(text);
}else if(text.size() == 14)
{
getvalidCNPJ(text);
}else{
system.debug('CPF/CNPJ Inválido');
}
}
}
But I get this error:
Uncaught Action failed: c:CEC_SearchAccountComponent$controller$handleClick [system is not defined]
Following the codes:
cmp--
<aura:component controller="CEC_SearchAccount" implements="force:appHostable">
<aura:attribute name="acctList" type="Account[]" />
<ui:inputText aura:id="searchText" label="Insira o CPF ou CNPJ" required="TRUE"/>
<lightning:button variant="brand" label="Buscar" onclick="{!c.handleClick}"/>
<aura:iteration items="{!v.acctList}" var="a">
<p>{!a.Name},{!a.Type}</p>
</aura:iteration>
</aura:component>
controller ---
({
/* Dentro da ação de clicar no botão, a classe controladora aponta para a função validKey*/
handleClick : function(component, event, helper) {
system.debug("Entrou na função HandleClick");
var input_text = component.get("v.searchText")
var action = component.get("c.validKey");
action.setParams({text:cmp.get("input_text")});
action.setCallback(this,function(response)
{
var state = response.getState();x
if(component.isValid() && STATE==Sucess){
component.set("v.acctList",response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Class--
public class CEC_SearchAccount{
public static List<Account> getfoundAccount(String[] Key, String documentType)
{
List<Account> Conta = [Select ID, Name, DocumentType__c,DocumentNumber__c,FormattedDocument__c,BillingAddress from Account
where DocumentNumber__c =:Key AND DocumentType__c =:documentType];
return Conta;
}
public static void getvalidCPF(String[] CPF)
{
/* Cálcula se o cpf é valido através do cálculo dos digitos validadores.*/
integer value;
integer coeff = 10, sum, rest;
String dig10,dig11;
//Calcula o primeiro digito validador do CPF
for(integer i=0; i<9;i++)
{
value = Integer.valueOf(cpf[i])* coeff;
coeff--;
sum = sum + value ;
}
rest = 11 - math.mod(sum,11);
if((rest == 10) || (rest == 11))
{
dig10 = '0';
}else{
dig10 = String.valueOf(rest);
}
sum = 0;
coeff = 11;
value = 0;
for(integer i=0;i<10;i++)
{
value = Integer.valueOf(cpf[i])*coeff;
coeff--;
sum = sum + value;
}
rest = 11 - math.mod(sum,11);
if((rest == 10) || (rest==11))
{
dig11 = '0';
}else{
dig11=String.valueOf(rest);
}
// Validate if the calculus match
if((dig11 == cpf[11]) && (dig10 == cpf[10]))
{
String documentType = 'CPF';
getfoundAccount(CPF,documentType);
}else{
system.debug('CNPJ iNVÁLIDO');
}
}
public static void getvalidCNPJ(String[]CNPJ)
{
integer value;
integer coeff=12,sum,rest;
String dig13,dig14;
for(integer i = 0; i < 12;i++)
{
value = Integer.valueOf(CNPJ[i]) * coeff;
coeff--;
sum = sum + value;
}
rest =Math.mod(sum,11);
if((rest == 0) || (rest == 1))
{
dig13 = '0';
}else{
dig13 = String.valueOf(11 - rest);
}
// Calculando o segundo digito verificador do CNPJ
rest=0;
coeff=13;
for(integer i = 0;i<13;i++)
{
value = Integer.valueOf(CNPJ[i]) * coeff;
coeff--;
sum = sum + value;
}
rest = math.mod(sum,11);
if((rest == 0) || (rest == 1))
{
dig14 = '0';
}else{
dig14 = String.valueOf(11 - rest);
}
if((CNPJ[13] == dig13) && (CNPJ[14] == dig14))
{
String documentType ='CNPJ';
getfoundAccount(CNPJ, documentType);
}else{
//
}
}
@AuraEnabled
Public static void getvalidKey(String[] text)
{
/*Após ler a string de caracteres, o sistema chama a função de cpf ou cnpj conformo o tamanho da string */
system.debug('Chegou na função da classe');
if(text.size() == 11)
{
getvalidCPF(text);
}else if(text.size() == 14)
{
getvalidCNPJ(text);
}else{
system.debug('CPF/CNPJ Inválido');
}
}
}
Raj Vakati
Use this code
Raj Vakati
In javascript you need to use console.log and not System.debug
Raj Vakati
Let me know any issue