You need to sign in to do that
Don't have an account?
Leticia Monteiro Freitas 4
Why my component.get doesent work?
Hello, I'm trying to make a Lightning component that makes a search in Account and returns results. But, I get the following error:
My variable input_text gets undefiened, even after user get.component.
Can anyone help me?
My code:
Class:
/*Versão 3.00 - US_179 - Leticia Freitas - 13/11
Classe que recebe uma string, determina se é um cpf ou um cnpj e a partir dele, realiza a busca dessa conta.
Caso exista o registro, retorna as informações: Nome, Tipo de Documento (CPF ou CNPJ), Número do documento, Número do Documento Formatado, Logradouro, CEP, Cidade e Estado.
*/
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.substring(i,1))* 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.substring(i,1))*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.substring(0,11)) && (dig10 == cpf.substring(0,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.substring(i,1)) * 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.substring(i,1)) * 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.substring(0,13) == dig13) && (CNPJ.substring(0,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 agora o/');
//integer tamanho = text.length();
system.debug('Tamanho:');
system.debug('Texto:'+text);
system.debug(text.length());
if(text.length() == 11)
{
getvalidCPF(text);
}else if(text.length() == 14)
{
getvalidCNPJ(text);
}else{
system.debug('CPF/CNPJ Inválido');
}
}
}
Controller:
({
/* Dentro da ação de clicar no botão, a classe controladora aponta para a função validKey*/
handleClick : function(component, event, helper) {
var action = component.get("c.getvalidKey");
var input_text = component.get("v.searchText");
console.log("input_text"+ input_text);
debugger;
action.setParams({"text":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);
}
})
Cmp:
<aura:component controller="CEC_SearchAccount" implements="force:appHostable">
<aura:attribute name="acctList" type="Account[]" />
<lightning:input name="searchText" label="Insira o CPF ou CNPJ" />
<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>
My variable input_text gets undefiened, even after user get.component.
Can anyone help me?
My code:
Class:
/*Versão 3.00 - US_179 - Leticia Freitas - 13/11
Classe que recebe uma string, determina se é um cpf ou um cnpj e a partir dele, realiza a busca dessa conta.
Caso exista o registro, retorna as informações: Nome, Tipo de Documento (CPF ou CNPJ), Número do documento, Número do Documento Formatado, Logradouro, CEP, Cidade e Estado.
*/
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.substring(i,1))* 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.substring(i,1))*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.substring(0,11)) && (dig10 == cpf.substring(0,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.substring(i,1)) * 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.substring(i,1)) * 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.substring(0,13) == dig13) && (CNPJ.substring(0,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 agora o/');
//integer tamanho = text.length();
system.debug('Tamanho:');
system.debug('Texto:'+text);
system.debug(text.length());
if(text.length() == 11)
{
getvalidCPF(text);
}else if(text.length() == 14)
{
getvalidCNPJ(text);
}else{
system.debug('CPF/CNPJ Inválido');
}
}
}
Controller:
({
/* Dentro da ação de clicar no botão, a classe controladora aponta para a função validKey*/
handleClick : function(component, event, helper) {
var action = component.get("c.getvalidKey");
var input_text = component.get("v.searchText");
console.log("input_text"+ input_text);
debugger;
action.setParams({"text":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);
}
})
Cmp:
<aura:component controller="CEC_SearchAccount" implements="force:appHostable">
<aura:attribute name="acctList" type="Account[]" />
<lightning:input name="searchText" label="Insira o CPF ou CNPJ" />
<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>
All Answers