function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ECoronaECorona 

Remove Time Stamp 00:00:00 from Field

Hello i have this trigger and works ok, the problem is that date field (not datetime) returns me the date in yyyy/mm/dd 00:00:00 format and i would like to get the date in DD/MM/YYYY format. This is the Date field Fecha_de_Vencimiento_de_Contrato__c

I will really appreciate your help

 List<Id> conIds = new List<Id>();
   
    if(trigger.isDelete){
        for(Proveedores__c c : Trigger.old){
            conIds.add(c.Cuenta__c);
        }
    }else{
        for(Proveedores__c c : Trigger.new){
        conIds.add(c.Cuenta__c);
        }
    }
    
    List<Account> ProveedoresAccount = [Select id, name, Proveedores_Resumen__c, (Select tipo_de_proveedor__c, Proveedores__c, 
                                        Fecha_de_Vencimiento_de_Contrato__c   from Proveedores__r) from Account where id in : conIds];   
    
    for(Account a: ProveedoresAccount){
        String Proveedores='';
        for(Proveedores__c pro : a.Proveedores__r){
            Proveedores=Proveedores+': '+pro.tipo_de_proveedor__c+': '+pro.Proveedores__c+': '+pro.Fecha_de_Vencimiento_de_Contrato__c +'/' ;       
        }
        a.Proveedores_Resumen__c= Proveedores;
        update(a);
    }
Best Answer chosen by ECorona
Nithesh NNithesh N
Try this.
for(Account a: ProveedoresAccount){
        String Proveedores='';
        for(Proveedores__c pro : a.Proveedores__r){
           String datevalue = 'No date Specified' ;
          if(pro.Fecha_de_Vencimiento_de_Contrato__c != null) {
            datevalue = String.valueOf(pro.Fecha_de_Vencimiento_de_Contrato__c.format());
          }
          Proveedores = 
                        Proveedores + ': ' + pro.tipo_de_proveedor__c +
                        ': '+pro.Proveedores__c + ': ' + datevalue +'/' ;       
        }
        a.Proveedores_Resumen__c = Proveedores;
        
        update(a);
    }

 

All Answers

Nithesh NNithesh N
Try This.....
for(Account a: ProveedoresAccount){
        String Proveedores='';
        for(Proveedores__c pro : a.Proveedores__r){
            Proveedores= Proveedores+': '+pro.tipo_de_proveedor__c+
            ': '+pro.Proveedores__c+': '+ pro.Fecha_de_Vencimiento_de_Contrato__c.format() +'/' ;       
        }
        a.Proveedores_Resumen__c= Proveedores;
        update(a);
    }

Let me know if it Works

Best, 
Nithesh
ECoronaECorona
Hello Nithesh! thank you for your response.
I get an error, i could save it, but when i try to save a "Proveedor"  i get System.NullPointerException: Attempt to de-reference a null object: 
Nithesh NNithesh N
Can you post the Complete Error Message?
 
ECoronaECorona
This is the error

El desencadenador Apex ResumenProveedores ha provocado una excepción inesperada. Póngase en contacto con su administrador: ResumenProveedores: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.ResumenProveedores: line 23, column 1

This is the line 23
 Proveedores=Proveedores+': '+pro.tipo_de_proveedor__c+': '+pro.Proveedores__c+': '+pro.Fecha_de_Vencimiento_de_Contrato__c.format()+'/' ;     
Nithesh NNithesh N
Try this.
for(Account a: ProveedoresAccount){
        String Proveedores='';
        for(Proveedores__c pro : a.Proveedores__r){
           String datevalue = 'No date Specified' ;
          if(pro.Fecha_de_Vencimiento_de_Contrato__c != null) {
            datevalue = String.valueOf(pro.Fecha_de_Vencimiento_de_Contrato__c.format());
          }
          Proveedores = 
                        Proveedores + ': ' + pro.tipo_de_proveedor__c +
                        ': '+pro.Proveedores__c + ': ' + datevalue +'/' ;       
        }
        a.Proveedores_Resumen__c = Proveedores;
        
        update(a);
    }

 
This was selected as the best answer
ECoronaECorona
Wow! thank you Nithesh it is working OK!
Nithesh NNithesh N
I am Glad that it Worked!
ECoronaECorona
yes! thank you so much ;)