+ Start a Discussion
Deloitte IT Admin 2Deloitte IT Admin 2 

Problem with Save method

Hi All,

i've got this Save method that gets called when users press a button. If users press it more than one time while the page is not completely loaded, this causes problems. 
Any idea on how to solve this issue? Here's the save method:
 
public PageReference save() {
    
        update ppl ;
        Boolean fyok = true;
        Set<Decimal> fypresent = new Set<Decimal>();
        for (Pipeline_Item__c pl: ppl.Pipeline_Items__r)
        {
            if (pl.Fiscal_Year__c!= null && pl.Fiscal_Year__c!= 0)
            {
                if (fypresent.contains(pl.Fiscal_Year__c)){
                  fyok = false;
                }
                fypresent.add(pl.Fiscal_Year__c);
          } 
        }
        if (fyok){
            for (Pipeline_Item__c pl: ppl.Pipeline_Items__r)
            {
                update pl;
            }
      }
      reload();
      update ppl ;

      fyok = true;
       fypresent = new Set<Decimal>();
        for (Pipeline_Item__c pl: ppl.Pipeline_Items__r)
        {
            if (pl.Fiscal_Year__c!= null && pl.Fiscal_Year__c!= 0)
            {
                if (fypresent.contains(pl.Fiscal_Year__c)){
                  fyok = false;
                }
                fypresent.add(pl.Fiscal_Year__c);
          }
        }
        if (fyok){
            for (Pipeline_Item__c pl: ppl.Pipeline_Items__r)
            {
                update pl;
            }
      }

       updateActualsMor();  
       return null;
     
        reload();
        return null;
    }