0

hi can someone help by telling me where i'm going wrong? I want to print the variable "cpf" in the vfp, but the develor doesn't find it. Starting now in salesforce, thanks for any help

Controller:

public class ImpressaoContratoController {
    public String idOpp {get; set;}
    public String tipoPedido {get; set;}
    public Date datapagamento {get; set;}
    public Date datacarregamento {get; set;}
    public Decimal precototal {get; set;}
    public transient DadosContratoVF_VO dadosContrato {get; private set;}
    public List <OpportunityLineItem> oppProduct {get;set;}
    public List <Opportunity> enderecoConta {get;set;}
    public String formatacpf {get;set;}
    String cpf;

    public String formatacpf (String cpf){
        return cpf.substring(0, 3) + '.' +
               cpf.substring(3, 6) + '.' +
               cpf.substring(6, 9) + '-' +
               cpf.substring(9, 11);
    }
    
    public List <Opportunity> getEndereco(){
        system.debug('idOpp= '+idOpp);
        if(enderecoConta == null) {
            enderecoConta = [SELECT Id, Recibidor_de_mercaderia__r.CEP__c, Recibidor_de_mercaderia__r.Rua__c, 
                             Recibidor_de_mercaderia__r.Municipio__r.Name, Recibidor_de_mercaderia__r.Bairro__c, 
                             Recibidor_de_mercaderia__r.Estado__c, Recibidor_de_mercaderia__r.Numero__c, owner.lastname,
                             owner.Email,owner.CPF__c 
                             FROM Opportunity 
                             WHERE Id =: idOpp
                             LIMIT 1];
        }
        cpf=formatacpf(enderecoConta[0].owner.CPF__c);
        system.debug('cpf= '+cpf);
        
        return enderecoConta;
    }

VFP:

<div style="float: right"><br/><br/>
   <table border="0" width="48%"   >  
      <tr>
         <th><b>Nome:&nbsp;</b></th>
         <td><apex:outputField value="{!Endereco[0].owner.lastname}"/></td>
      </tr>                            
      <tr>
         <th><b>CPF:&nbsp;</b></th>
         <td><apex:outputText value="{!Endereco.cpf}"/></td>
      </tr>
      <tr>
         <th><b>e-mail:&nbsp;</b></th>
         <td><apex:outputField value="{!Endereco[0].owner.Email}"/></td>
      </tr>
   </table>
</div>

1 Answer 1

0

If you want to display the field, you need to use __c:

<td><apex:outputText value="{!Endereco.cpf__c}"/></td>

To display the string you defined, you need to make it public and have a getter:

<td><apex:outputText value="{!cpf}"/></td>

...

public String cpf { get; set; }
1
  • wow... you are amazing, thank you so much again!! I even started following you on twitter and github
    – Souza
    Commented Sep 30, 2021 at 20:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .