• Yeyeric
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
Hello,

I'm a beginner in APEX and looking to do a basic loop.

Here is my situation. I have 2 fields, start date and end date

I want to do a loop for each month of the period between start and end date.
If more details are needed, start and end date are always 1st of month as per my criteria, and I need to do a basic calculation but I'm stuck with the setting of the loop.

How would you suggest to do this ?

I've been trying to think of something but I can't figure out

Thanks a lot
Hello,

I'm working on a visualforce page. At the moment, it only has 2 colomns with the name of the field and the values displayed. (In my screenshot, it's the lines  with 24 mois, 36 mois or 48 mois.)

However, I would need to add a third column, with the name of the field and also its values. What I've done is adding a "page blocksection columns = 3" but this makes the result very bad looking, with bad gaps between fields. I would like those fields to be with a normal gap, I don't know how I can do.

Here is the screenshot : User-added image

And here is the code (I've only gone until the 24mois line as it's the same for 36 and 48)
<apex:pageblocksection columns="1" title="{!$Label.PRICER_Parametres_offres}" collapsible="true" showHeader="true">
            <apex:pageblocksection columns="2">
                <apex:pageblocksectionitem >
                    <apex:outputlabel for="IdDateDebutContrat" value="{!$ObjectType.Offre__c.Fields.DateDedebut__c.label}"/>
                    <apex:selectList id="IdDateDebutContrat" value="{!oOfferOptionDM.sDateDebutContrat}" size="1">
                        <apex:selectOptions value="{!oOfferOptionDM.lDateDebutContrat}"/>
                    </apex:selectList>
                </apex:pageblocksectionitem>
                <apex:pageblocksectionitem >
                    <apex:outputlabel for="IdDateValidite" value="{!$ObjectType.Ref_Config_Pricer__c.Fields.Date_validite_offre__c.label}"/>
                    <apex:outputText id="IdDateValidite" value="{!oOfferOptionDM.sDateValiditeOffre}"/>
                </apex:pageblocksectionitem>
                <apex:pageblocksectionitem >
                    <apex:pageblocksection columns="3" >
                    <apex:pageblocksectionitem >    
                        <apex:outputlabel for="Id12Mois" value="{!$ObjectType.Offre__c.Fields.X12_mois__c.label}" />            
                        <apex:inputField id="Id12Mois" value="{!oOfferOptionDM.oOffer.X12_mois__c}"/>
                    </apex:pageblocksectionitem>
                    <apex:pageblocksectionitem >
                        <apex:outputlabel for="IdMarge12Mois" value="{!$ObjectType.Offre__c.Fields.TECH_Marge_12_mois_EMWh__c.label}" styleClass="labelCol"/>
                        <apex:inputField id="IdMarge12Mois" value="{!oOfferOptionDM.oOffer.TECH_Marge_12_mois_EMWh__c}"/>
                    </apex:pageblocksectionitem>
                    <apex:pageblocksectionitem >
                        <apex:outputlabel for="IdMarge12Mois" value="{!$ObjectType.Offre__c.Fields.TECH_BC_12_mois_EMWh__c.label}" styleClass="labelCol"/>
                        <apex:inputField id="IdMarge12Mois" value="{!oOfferOptionDM.oOffer.TECH_BC_12_mois_EMWh__c}"/>
                    </apex:pageblocksectionitem>
                    </apex:pageblocksection>
                </apex:pageblocksectionitem>

<apex:pageblocksectionitem >    
                        <apex:outputlabel for="Id24Mois" value="{!$ObjectType.Offre__c.Fields.X24_mois__c.label}"/>         
                        <apex:inputField id="Id24Mois" value="{!oOfferOptionDM.oOffer.X24_mois__c}"/>
                    </apex:pageblocksectionitem>
                    <apex:pageblocksectionitem >
                        <apex:outputlabel for="IdMarge24Mois" value="{!$ObjectType.Offre__c.Fields.TECH_Marge_24_mois_EMWh__c.label}" styleClass="labelCol"/>                   
                        <apex:inputField id="IdMarge24Mois" value="{!oOfferOptionDM.oOffer.TECH_Marge_24_mois_EMWh__c}"/>
                    </apex:pageblocksectionitem>
                </apex:pageblocksectionitem>

Thanks for your help
 
Hello,

I'm trying to release a new dev made in sandbox. One of the class had already been released in prod from the sandbox but it's not blocking.

Here is the error message I get :

Failure Message: "System.NullPointerException: Attempt to de-reference a null object", Failure Stack Trace: "Class.PricerOffer.firstList: line 177, column 1 Class.PricerController_TEST.pricerControllerTest: line 52, column 1"

And here is the code of the test until some lines below the line 52:

@isTest
public class PricerController_TEST {

  // -------------------------------------
    // pricerControllerTest() method
    // ------------------------------------- 
  static testMethod void pricerControllerTest() {
    // Data Model
    PricerUtils_TEST.loadPricerData();
   
    test.startTest();
   
        PageReference oPageRef = new PageReference('/apex/Pricer?oppId=' + PricerUtils_TEST.oOpp.Id);
        test.setCurrentPageReference(oPageRef);
        PricerController oPricerController = new PricerController();
        PricerSiteOffer.bIsTest = true;
       
        system.debug(Logginglevel.ERROR, '### SFDC - PricerController_TEST - pricerControllerTest() - PricerUtils_TEST.lRV.size():' + PricerUtils_TEST.lRV.size());
   
    // Initializing  Pricer options
    oPricerController.oOfferOption.sDateDebutContrat = String.valueOf(system.today().toStartOfMonth());
    oPricerController.oOfferOption.oOffer.X12_mois__c = true;
    oPricerController.oOfferOption.oOffer.X24_mois__c = false;
    oPricerController.oOfferOption.oOffer.X36_mois__c = false;
    oPricerController.oOfferOption.oOffer.X48_mois__c = false;
    oPricerController.oOfferOption.oOffer.TECH_Duree_mois__c = '12';
    oPricerController.oOfferOption.oOffer.Cout_variable_transport__c = 'Oui';
    oPricerController.oOfferOption.oOffer.Offre_regulee__c = 'Oui';
    oPricerController.oOfferOption.oOffer.Copropriete_Clinique_Public__c = 'Oui';
    oPricerController.oOfferOption.oOffer.Assujetti_TVA__c = true;
    system.assertEquals(PricerController.bBatchSendEmail, true);
    system.assertNotEquals(PricerOption.lDateDebutContrat.size(), 0);
    system.assertNotEquals(PricerOption.sDateValiditeOffre, null);
    system.assertNotEquals(PricerOption.sDateFinMaxOffre, null); 
   
    // Execute Pricer
    oPricerController.executeBatchOrNot();
    system.assertEquals(oPricerController.oOfferOption.lOffer.size(), 2);
   
    integer i=0;
        for (PricerOffer oPricerOffer:oPricerController.lOffer){
      system.assertequals(oPricerOffer.iNbExistingSiteOffer, 3);
     
      // Save offer
            oPricerOffer.saveOffer();
           
            // Pagination functionality
            if(i==0){
              system.assertNotEquals(PricerOffer.DISPLAYSITEDETAIL, null);
              system.assertNotEquals(PricerOffer.NBSITESAVECDETAIL, null);
             
              oPricerOffer.firstList();
              oPricerOffer.nextList();
              oPricerOffer.previousList();
              oPricerOffer.lastList();
            }           
            i++;
        }

I'm not a dev but I'm surprised this is now posing problem because before it has been released ok. Also, our salesforce org hasn't changed much, although we created some unique IDs which were posing problems but I removed them and the test is now failing only at this step.

Thanks for your help

Regards,