1

I have a visualforce page where I insert 7 records at once. Each record has 14 fields.

When I only seize some of the fields, the query works, the 7 records are created. But when I seize more, the query doesn't work. There is no redirection. no exeption.

edit: here is the code

public PageReference saveImmo() {


    Date debutDate = Date.parse('1/1/'+Year);

    Map<String,Map<String,Decimal>> listMap = new Map<String,Map<String,Decimal>>();

    listMap.put('MONTANT BRUT DEBUT EXERCICE',m1);
    listMap.put('AUGMENTATION Acquisition',m2);
    listMap.put('AUGMENTATION Production',m3);
    listMap.put('AUGMENTATION Virement',m4);
    listMap.put('DIMINUTION Cession',m5);
    listMap.put('DIMINUTION Retrait',m6);
    listMap.put('DIMINUTION Virement',m7); 

    for (String key : listMap.keySet()) {

        T4_IMMO__c immo1 = new T4_IMMO__c();
        immo1.IF__c = IdFisc;
        immo1.Exercice_debut__c = debutDate;
        immo1.Colonne__c = key;

        Map<String,Decimal> m1 = listMap.get(key);

        immo1.Frais_pr_liminaires__c=m1.get('Frais_pr_liminaires__c');
        immo1.Charges_repartir_plusieurs_exercices__c = m1.get('Charges_repartir_plusieurs_exercices__c');  
        immo1.Primes_de_remboursement_des_obligations__c = m1.get('Primes_de_remboursement_des_obligations__c');
        immo1.Immobilisation_recherche_d_veloppement__c = m1.get('Immobilisation_recherche_d_veloppement__c');
        immo1.Brevets_marques_droits_et_similaires__c = m1.get('Brevets_marques_droits_et_similaires__c');
        immo1.Fonds_commercial__c = m1.get('Fonds_commercial__c');
        immo1.Autres_immobilisations_incorporelles__c = m1.get('Autres_immobilisations_incorporelles__c');
        immo1.Terrains__c = m1.get('Terrains__c');
        immo1.Constructions__c = m1.get('Constructions__c');
        immo1.Installat_tech_mat_riel_et_outillage__c = m1.get('Installat_tech_mat_riel_et_outillage__c');
        immo1.Mat_riel_de_transport__c = m1.get('Mat_riel_de_transport__c');
        immo1.Mobilier_mat_riel_bureau_et_am_nagement__c = m1.get('Mobilier_mat_riel_bureau_et_am_nagement__c');
        immo1.Autres_immobilisations_corporelles__c = m1.get('Mobilier_mat_riel_bureau_et_am_nagement__c');
        immo1.Immobilisations_corporelles_en_cours__c = m1.get('Immobilisations_corporelles_en_cours__c');  

        insert immo1;

    }

    return Page.Allimmossaved;
    }
}

page:

<apex:pageBlockTable value="{!listLabels}" var="dirKey" width="100%" columnsWidth="20%,10%,10%,10%,10%,10%,10%,10%">
<apex:column >
<apex:facet name="header">
<center> Nature </center> </apex:facet>
{!$ObjectType.T4_IMMO__c.fields[dirKey].label}
</apex:column>

<apex:column >
<apex:facet name="header">
       <center> Montant Brut <br/>
        Début de l'exercice </center>
     </apex:facet> 
<apex:inputText value="{!m1[dirKey]}" styleClass="myClass"/>
</apex:column>

<apex:column >
<apex:facet name="header">
       <center> Augmentation <br/>
        Acquisition </center>
     </apex:facet> 
<apex:inputText value="{!m2[dirKey]}" styleClass="myClass"/>
</apex:column>

<apex:column >
<apex:facet name="header" >
        <center>Augmentation <br/>
        Production <br/>
        de l'entreprise<br/>
         pour elle-même</center> 
     </apex:facet> 
<apex:inputText value="{!m3[dirKey]}" styleClass="myClass"/>
</apex:column>

<apex:column >
<apex:facet name="header" >
        <center>Augmentation <br/>
        Virement 
        </center>
     </apex:facet> 
<apex:inputText value="{!m4[dirKey]}" styleClass="myClass"/>
</apex:column>


<apex:column >
<apex:facet name="header" >
        <center>Diminution <br/>
        Cession 
        </center>
     </apex:facet> 
<apex:inputText value="{!m5[dirKey]}" styleClass="myClass"/>
</apex:column>

<apex:column >
<apex:facet name="header" >
        <center>Diminution <br/>
        Retrait 
        </center>
     </apex:facet> 
<apex:inputText value="{!m6[dirKey]}" styleClass="myClass"/>
</apex:column>

<apex:column >
<apex:facet name="header" >
        <center>Diminution <br/>
        Virement
        </center>
     </apex:facet> 
<apex:inputText value="{!m7[dirKey]}" styleClass="myClass"/>
</apex:column>

</apex:pageBlockTable>
<apex:pageBlockButtons >

<apex:commandButton value="Sauvegarder" action="{!saveImmo}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

EDIT: Fixed the problem! Turns out I was putting numbers with 10005,24 instead of 10005.24. and this is why I couldn't insert the records

3
  • Pls share some code else this is very unclear Commented May 8, 2015 at 20:46
  • I've added the code, hope it's more clear now
    – Yousra
    Commented May 8, 2015 at 20:53
  • Can you post your debug log?
    – navD87
    Commented May 8, 2015 at 21:06

2 Answers 2

3

I have a few suggestions on how you can improve the code and debug this.

1) As Victor stated, create a list of T4_IMMO__c (List<T4_IMMO__c> recordsToInsert) to insert and move the insert statement out from the for loop.

2) Wherever possible use SObject get, put methods to set your field values.

eg:-

for(String fieldName : m1.keySet()){
    immo1.put(fieldName, m1.get(fieldName));
}

3)Use Database.insert to insert the records:

Database.SaveResult[] insertResults = Database.insert(recordsToInsert, false);

Then check the insert operations' results by

for(Database.SaveResult result : insertResults) {
     if(!result.isSuccess()) {
         System.debug(result.getErrors()[0].getMessage());
     }
}

If you can't figure out what's wrong by the error messages printed, post the debug log.

4
  • it displays this error 23:37:34.143 (143296418)|FATAL_ERROR|System.ListException: List index out of bounds: 0
    – Yousra
    Commented May 8, 2015 at 22:45
  • I forget to add a check for proper inserts in the code. Check the new code
    – navD87
    Commented May 8, 2015 at 22:49
  • it displays no error, still the same old debug log. with less numbers it works.
    – Yousra
    Commented May 8, 2015 at 23:20
  • Fixed the problem! Turns out I was putting numbers with 10005,24 instead of 10005.24
    – Yousra
    Commented May 9, 2015 at 6:57
1

Your insert statement is inside for loop. That is not a best practice. It will call insert statements as many times as the length of map. Declare a list of T4_IMMO__c add the instances to the list and finally call insert only once outside the loop.

But this will not address your problem. Could you please post debug log also.

1
  • Added the debug log
    – Yousra
    Commented May 8, 2015 at 21:36

You must log in to answer this question.

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