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
Cesar Ramirez Vasquez005391619375684564Cesar Ramirez Vasquez005391619375684564 

Im unable to fin what im doing wrong my method save and back dont work any ideas ?

Controller

public class convertirFactura {


      public Cotizacion__c cotizacion { get; set; }
      public List<Lineas__c> lineaC { get; set; }
      public Factura__c factura { get; set; }
      public LineaF__c lineaF { get; set; }
      public Cliente__c cliente { get; set; }
      public Date Today { get { return Date.today(); }}

      
    public PageReference init() {
   
        Id cotizacionId;
       
        //REMOVE AFTER DEV
       
        if(System.currentPagereference().getParameters().get('cotizacionId')==null){
  
             cotizacionId = [select id from Cotizacion__c limit 1].id;  
        }
        else{
            //param from URL
            cotizacionId = System.currentPagereference().getParameters().get('cotizacionId');
        }
       
        cotizacion = new Cotizacion__c();
        //se cargan los fields que se van ha usar del candidato
        cotizacion = [select id, name, Comentarios__c,Email__c,Estado__c, NombreLead__c, Apellidos__c, PorcentajeImpuestos__c from Cotizacion__c where Id= :cotizacionId];
        lineaC = new List<Lineas__c>();
        for (Lineas__c  L : [select CantidadCajas__c, CantidadUnidades__c, Cotizacion__c, Producto__c, Total_Costos_Linea__c, TtotalVentaLinea__c from Lineas__c where Cotizacion__r.id =:cotizacionId]) {
           
         if (L != null){
          lineaC.add(L);
                       }
                           }
        //initialize the variables
       
        factura = new Factura__c();
        cliente = new Cliente__c();
                            
        factura.Comentarios__c = cotizacion.Comentarios__c;
        factura.Estado__c = cotizacion.Estado__c;
        factura.PorcentajeDescuento__c = cotizacion.PorcentajeImpuestos__c ;
        factura.Fecha_de_Entrega__c = Today;
       
        cliente.Name = cotizacion.NombreLead__c;
        cliente.Apellidos__c = cotizacion.Apellidos__c;
      
  
       
       
       
        back();
       
        return null;
    }

    //insert the new objects and create the lines assingned to the invoice
    public PageReference save() {
      
      
        insert cliente;
      
        factura.Cliente__c = cliente.id;
      
        insert factura;
       
        List <LineaF__c> linFactura = new List <LineaF__c>();
       
        for (lineas__c L : lineaC){
       
        if (L != null){
       
           for(Integer i =0; i < lineaC.size();i++){
       
        lineaF = new LineaF__c();
        lineaF.CantidadCajas__c = L.CantidadCajas__c;
        lineaF.CantidadUnidades__c = L.CantidadUnidades__c;
        lineaF.Factura__c = factura.id;
        lineaF.Producto__c = L.Producto__c;
        lineaF.Total_Costos_Linea__c = L.Total_Costos_Linea__c;
        lineaF.Total_Venta_Lineas__c = L.TtotalVentaLinea__c ;
      
        linFactura.add(lineaF);
       
        Producto__c P = new Producto__c();
        P =[select id, InventarioCajas__c, InventarioUnidades__c from Producto__c where id=:L.Producto__c limit 1];
        P.InventarioCajas__c = P.InventarioCajas__c - L.CantidadCajas__c;
        P.InventarioUnidades__c = P.InventarioUnidades__c - L.CantidadUnidades__c;
       
        Update (P);
        }
      
        }
     }
       
        insert(lineaF);
       

        Pagereference p = new Pagereference('/' + factura.id);
        return p;
    }
    
        public PageReference back() {
            Pagereference p = new Pagereference('/' + cotizacion.id);
            return p;
    }
}
Vamsi KrishnaVamsi Krishna
do you get any error from these methods ?
try adding some System.debug statements and capture your variable values.. it will give you more details on where your code might be failing..
Cesar Ramirez Vasquez005391619375684564Cesar Ramirez Vasquez005391619375684564
Im getting error from save () method, null pointer exeption and the method back() is not working when press the the button on my vf page only refresh the page no sure why ?
How can i capture my variables, im pretty new to apex, i will research about system.debug. Thanks for your reply