+ Start a Discussion
Vianney Bancillon 8Vianney Bancillon 8 

Error: Erreur de compilation : Field is not writeable: Opportunity.CreatedDate à la ligne 21 colonne 17

Hi Everyone,

I'm trying to write a simple test class.
My code gives the said error.
In my mind, at the line 21, I don't write an update on the CloseDate field but just a condition (boolean).
What is wrong in the following code?
 
@istest

public class batchOppBisTest {
    static testMethod void validateBatch(){
    
    //création d'une nouvelle opportunité qui répond aux critères du workflow
    
    Opportunity opp1 = new Opportunity (Name = 'opptyDeTest', CloseDate = date.TODAY()+45, Engagement_date_finalisation_commande__c = date.TODAY()-1, StageName='Au planning de livraison');
    
    insert opp1;
        
    //vérification que Nbre de jours avant finalisation a été calculé
    System.debug ('$$$ Nbre de jours avant finalisation' + opp1.Nbre_Jours_Avant_Finalisation__c);
    
    //requête sur opportunités
    
    Opportunity [] tabOpp = [SELECT StageName, CreatedDate FROM Opportunity WHERE StageName = 'Au planning de livraison'];
    Opportunity [] oppCreated = new Opportunity []{};
       for (Opportunity o : tabOpp){
            if (o.CreatedDate = date.Today()){
            oppCreated.add(o);
            System.debug(o);
            }//if
       }//for    
          
    }//validateBatch
    
}//class

Thanks for your help!



 
Best Answer chosen by Vianney Bancillon 8
harshad kokateharshad kokate
Try Adding the if (o.CreatedDate == date.Today()){

on line no 20 

All Answers

harshad kokateharshad kokate
Try Adding the if (o.CreatedDate == date.Today()){

on line no 20 
This was selected as the best answer
Vianney Bancillon 8Vianney Bancillon 8
Thanks a lot harshad kokate