• bryansosa01
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 8
    Replies

Here is my code:  

 

global class CalculoPanjer implements Database.Batchable < sObject > {


    global final Date fechaal;
    global final string query;




    global Database.QueryLocator start(Database.BatchableContext BC) {


        return Database.getQueryLocator(query);
    }




    global void execute(Database.BatchableContext BC, List < sObject > scope) {
        List < Panjer__c > accns = new List < Panjer__c > ();

        double acom = 0;


        for(sObject s: scope) {

            Panjer__c a = (Panjer__c) s;
            if(a.Fecha_al__c == fechaal && a.n__c > 0) {


                    List < Cartera_por_Banda__c >
                    cpb = [SELECT j__c, vj__c, ej__c, uj__c
                        FROM Cartera_por_Banda__c
                        WHERE Fecha_al__c = : a.Fecha_al__c and j__c <= : a.n__c
                        ORDER BY j__c ];

            

                double acomAn = 0;





                for( Cartera_por_Banda__c c : cpb) {

                  List <Panjer__c>
                        cpb2 = [SELECT An__c
                            FROM Panjer__c
                            WHERE Fecha_al__c = : a.Fecha_al__c and n__c <= : a.n__c - c.vj__c  ];

                    


                    for(  Panjer__c  c2 : cpb2) {

                        acomAn += (c.ej__c / a.n__c) * c2.An__c;
                    }


                }




                a.An__c = acomAn;




                acom += a.An__c;
                a.Acumulado__c = acom;




                accns.add(a);
            }
        }

        update accns;

    }




    global void finish(Database.BatchableContext BC) {

       
    }


}

 

 

I need to make a query per each of the upper level loops. With this code I am passing the governor limits. Maybe with Dynamic queries or Maps, but I have no idea of how to do it.

 

Can anyone help me to improve my code, solving the 200 query limit. I would relly appreciate it.

I want tu SUM the MAX values from an Object

 

I want to do something like this:

SELECT sum(max(Exposici_n__c)) FROM  Cartera_de_Credito__c WHERE Fecha_al__c = 2013-06-30  Group BY Banda_2__c  ORDER BY Max(Banda__c)

 

 

Please help.

Bryan Sosa.

I want tu SUM the MAX values from an Object

 

I want to do something like this:

SELECT sum(max(Exposici_n__c)) FROM  Cartera_de_Credito__c WHERE Fecha_al__c = 2013-06-30  Group BY Banda_2__c  ORDER BY Max(Banda__c)

 

 

Please help.

Bryan Sosa.

 Is there eny way to improve my code in order to process about 30,000 records.

 

I would appreciate your help.

 

trigger SetPorcentajesdePerdidasEnCartera on RORAC__c (after insert) {

    
    for (RORAC__c rorac : System.Trigger.new) {
        
        for( Cartera_de_Credito__c cartera: [select id, Fecha_al__c, 
                                            Perdida_Esperada_p_Garant_a_Hipotec__c,
                                            Perdida_Esperada_p_Garant_a_Prendaria__c, 
                                            Perdida_Esperada_p_Garant_a_Hipotecaria__c
                                            from Cartera_de_Credito__c where Fecha_al__c =: rorac.Fecha_al__c ])
        {
                cartera.Perdida_Esperada_p_Garant_a_Hipotec__c = rorac.Perdida_Esperada_p_Garant_a_Hipotecaria__c;
                cartera.Perdida_Esperada_p_Garant_a_Prendaria__c = rorac.Perdida_Esperada_p_Garant_a_Prendaria__c ;
                cartera.Perdida_Esperada_p_Garant_a_Hipotecaria__c = rorac.Perdida_Esperada_p_Garant_a_Hipotecaria__c;
            
        update cartera;    
        }   
        
    } 
    }

 

I have two custom Objects with the following fields:

CustomObject1 with the fields Amount and Date1

CustomObject2 with the fields TotalAmount and Date 2

 

 

What I want to make is a trigger that summarizes CustomObject1.Amount  and save the result into CustomObject2.TotalAmount  where CustomObject1.Date1 =CustomObject2.Date2

 

 CustomObject1 and CustomObject2 are NOT related.

 

I would really appreciate your help. Thanks.

I want to make a trigger that summarizes field_A from CustomObject1 and save the result into Field_B from CustomObject2.

 

These objects are NOT related.

 

Can someone give me an example?

Here is my code:  

 

global class CalculoPanjer implements Database.Batchable < sObject > {


    global final Date fechaal;
    global final string query;




    global Database.QueryLocator start(Database.BatchableContext BC) {


        return Database.getQueryLocator(query);
    }




    global void execute(Database.BatchableContext BC, List < sObject > scope) {
        List < Panjer__c > accns = new List < Panjer__c > ();

        double acom = 0;


        for(sObject s: scope) {

            Panjer__c a = (Panjer__c) s;
            if(a.Fecha_al__c == fechaal && a.n__c > 0) {


                    List < Cartera_por_Banda__c >
                    cpb = [SELECT j__c, vj__c, ej__c, uj__c
                        FROM Cartera_por_Banda__c
                        WHERE Fecha_al__c = : a.Fecha_al__c and j__c <= : a.n__c
                        ORDER BY j__c ];

            

                double acomAn = 0;





                for( Cartera_por_Banda__c c : cpb) {

                  List <Panjer__c>
                        cpb2 = [SELECT An__c
                            FROM Panjer__c
                            WHERE Fecha_al__c = : a.Fecha_al__c and n__c <= : a.n__c - c.vj__c  ];

                    


                    for(  Panjer__c  c2 : cpb2) {

                        acomAn += (c.ej__c / a.n__c) * c2.An__c;
                    }


                }




                a.An__c = acomAn;




                acom += a.An__c;
                a.Acumulado__c = acom;




                accns.add(a);
            }
        }

        update accns;

    }




    global void finish(Database.BatchableContext BC) {

       
    }


}

 

 

I need to make a query per each of the upper level loops. With this code I am passing the governor limits. Maybe with Dynamic queries or Maps, but I have no idea of how to do it.

 

Can anyone help me to improve my code, solving the 200 query limit. I would relly appreciate it.

I want tu SUM the MAX values from an Object

 

I want to do something like this:

SELECT sum(max(Exposici_n__c)) FROM  Cartera_de_Credito__c WHERE Fecha_al__c = 2013-06-30  Group BY Banda_2__c  ORDER BY Max(Banda__c)

 

 

Please help.

Bryan Sosa.

I want tu SUM the MAX values from an Object

 

I want to do something like this:

SELECT sum(max(Exposici_n__c)) FROM  Cartera_de_Credito__c WHERE Fecha_al__c = 2013-06-30  Group BY Banda_2__c  ORDER BY Max(Banda__c)

 

 

Please help.

Bryan Sosa.

 Is there eny way to improve my code in order to process about 30,000 records.

 

I would appreciate your help.

 

trigger SetPorcentajesdePerdidasEnCartera on RORAC__c (after insert) {

    
    for (RORAC__c rorac : System.Trigger.new) {
        
        for( Cartera_de_Credito__c cartera: [select id, Fecha_al__c, 
                                            Perdida_Esperada_p_Garant_a_Hipotec__c,
                                            Perdida_Esperada_p_Garant_a_Prendaria__c, 
                                            Perdida_Esperada_p_Garant_a_Hipotecaria__c
                                            from Cartera_de_Credito__c where Fecha_al__c =: rorac.Fecha_al__c ])
        {
                cartera.Perdida_Esperada_p_Garant_a_Hipotec__c = rorac.Perdida_Esperada_p_Garant_a_Hipotecaria__c;
                cartera.Perdida_Esperada_p_Garant_a_Prendaria__c = rorac.Perdida_Esperada_p_Garant_a_Prendaria__c ;
                cartera.Perdida_Esperada_p_Garant_a_Hipotecaria__c = rorac.Perdida_Esperada_p_Garant_a_Hipotecaria__c;
            
        update cartera;    
        }   
        
    } 
    }

 

I want to make a trigger that summarizes field_A from CustomObject1 and save the result into Field_B from CustomObject2.

 

These objects are NOT related.

 

Can someone give me an example?