function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deloitte IT Admin 2Deloitte IT Admin 2 

System.LimitException: DML currently not allowed

Hi, I'm trying to write into a field, Actuals_P1_MOR__c, the number 100 (for example). This field belong to Pipeline_Item__c object. So, at the end, I update the List pl that is made of Pipeline_Item__c records, in order to update every Actuals_P1_MOR__c.

But I get this error:

System.LimitException: DML currently not allowed 
 
for (Pipeline_Item__c p : pl)
            {
                
                if (p.Actual_P1_MOR__c== null){
                    p.Actual_P1_MOR__c=0;
                }

                if (p.Pipeline__r.CurrencyIsoCode=='USD')
                {
                    p.Rate_to_USD__c=1;

                } else {

                    p.USD_MOR_1__c=morMap.get('January');
                    p.USD_MOR_2__c=morMap.get('February');
                    p.USD_MOR_3__c=morMap.get('March');

                    
                
                 if (p.Pipeline__r.CurrencyIsoCode=='EUR')
                {
                    String cic = 'EUR';
                    
                    p.Rate_to_USD__c= bemap.get(cic);
                   

                }
                else if (p.Pipeline__r.CurrencyIsoCode=='BRL')
                {
                    String cic = 'BRL';
                    
                    p.Rate_to_USD__c= bemap.get(cic);
                }
                else if (p.Pipeline__r.CurrencyIsoCode=='CAD')
                {
                    String cic = 'CAD';
                    
                    p.Rate_to_USD__c= bemap.get(cic);
                }
                else if (p.Pipeline__r.CurrencyIsoCode=='PLN')
                {
                    String cic = 'PLN';
                    
                    p.Rate_to_USD__c= bemap.get(cic);
                }
                else if (p.Pipeline__r.CurrencyIsoCode=='GBP')
                {
                    String cic = 'GBP';
                    
                    p.Rate_to_USD__c= bemap.get(cic);
                }
            }

                if (p.Estimate1__c != null)
                q.Estimate__c += p.Estimate1__c* p.Rate_to_USD__c;

                if (p.Op_P1__c != null)
                q.OP__c += p.Op_P1__c* p.Rate_to_USD__c;

                if (p.Op_P2__c != null)
                q.OP__c += p.Op_P2__c* p.Rate_to_USD__c;

                if (p.Op_P3__c != null)
                q.OP__c += p.Op_P3__c* p.Rate_to_USD__c;

                
                
                if (p.Actual_P1__c != null){                       
                    q.Month1__c += p.Actual_P1__c* p.Rate_to_USD__c;
                    
                    if (p.USD_MOR_1__c != null){
                        
                        q.Month1MOR__c += p.Actual_P1__c*p.USD_MOR_1__c;
                        p.Actual_P1_MOR__c += 100;
                       
                        
                    } else {
                        q.Month1MOR__c = q.Month1__c;

                    }               
                }

                if (p.Actual_P2__c != null){
                q.Month2__c += p.Actual_P2__c* p.Rate_to_USD__c;
                    if (p.USD_MOR_2__c != null){
                        q.Month2MOR__c += p.Actual_P2__c*p.USD_MOR_2__c;
                    } else {
                        q.Month2MOR__c = q.Month2__c;
                    }            
                }
                if (p.Actual_P3__c != null) {
                q.Month3__c += p.Actual_P3__c* p.Rate_to_USD__c;
                    if (p.USD_MOR_3__c != null){
                        q.Month3MOR__c += p.Actual_P3__c*p.USD_MOR_3__c;
                    } else {
                        q.Month3MOR__c = q.Month3__c;
                    }         
               }


            } 

            update pl;             <---------------------------------

Any idea?

Thankyou!
Nitin PaliwalNitin Paliwal
Hi,
Is this code return in some trigger?

Thanks
Nitin
Deepak Kumar ShyoranDeepak Kumar Shyoran
 Is this code in a Constructor or in a component Controller ?
Deloitte IT Admin 2Deloitte IT Admin 2
It is not in a trigger and I'm in a component.

 
Nitin PaliwalNitin Paliwal
In the component markup , set "allowDML = true".

<apex:component controller="Edit_Controller" allowDML="true">

It will solve your problem.

Thanks
NItin
Deloitte IT Admin 2Deloitte IT Admin 2
ok, and what if I were on a constructor?

 
Deepak Kumar ShyoranDeepak Kumar Shyoran
You can't perform a DML inside a controller. For that you need to create a separate method and need to call that from <apex:page controller ="Controller" action="{!yourMethodName}" />