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
Naveen KvpNaveen Kvp 

Field is not writeable

I am trying to map total formula field in class but it will through error like this :Error: NewOrderPageClass Compile Error: Field is not writeable: Order_Product__c.Total__c at line 54 column 14
  can you please suggest me how to resolve this issue.

public with sharing class NewOrderPageClass
{
  public Id orid{get;set;}
  // public List<id> Opids{get;set;}
  Public Map<id,Account> mapAccounts{get;set;}
  public Order__c OppId{get;set;}
  public List<Order_Product__c> oplist{get;set;}
  public List<Product_Master__c> Pmid{get;set;}
  public NewOrderPageClass(ApexPages.StandardController controller)
      {
      try
          {
       String orid=ApexPages.CurrentPage().getParameters().get('id');
       mapAccounts=new Map<id,Account>([Select id,Name,RollupOrders__c from Account]);
       oplist=new List<Order_Product__c>();
       OppId=[select id,name,Account__c,Total_Quantity_Sets__c,Total_Order_Amount__c from Order__c where id=:orid];
            Pmid=[select id,name,Active__c,Size_S__c,Size_L__c,Size_M__c,Total__c,Size_XL__c,Size_XXL__c,Price__c,Product_Color__c,Remarks__c   from Product_Master__c WHERE
                    Product_Type__c='Sales' AND Active__c=True AND Thermax__c=False ORDER BY CreatedDate ASC];
       System.Debug('----->>>>>@@@@Size'+Pmid.size());
       System.Debug('----->>>>>@@@@Prose'+Pmid);
          }
        
      catch(Exception e)
          {
          system.debug(e);
          ApexPages.addMessages(e);
          }
      }
    public PageReference CreateOrderProduct()
        {
       try
         {
       for( Product_Master__c p:pmid)
         {
        
         if(p.Size_S__c>0||p.Size_L__c>0||p.Size_M__c>0||p.Size_XL__c>0||p.Size_XXL__c>0)
         {
          RecordType rty = [SELECT Name, id FROM RecordType WHERE sObjectType='Order_Product__c' and name='Sales'];
          System.debug('-------------------> Record Type Ids'+rty);
           Order_Product__c op=new Order_Product__c(RecordTypeId=rty.id);             
             op.Product_Master__c=p.id;
             op.Sales_Order__c=OppId.id;
            // op.name=p.Name;      
             op.Size_S__c= p.Size_S__c;
             op.Size_M__c= p.Size_M__c;
             op.Size_L__c= p.Size_L__c;
             op.Size_XL__c= p.Size_XL__c;
             op.Size_XXL__c= p.Size_XXL__c;
             op.Total__c = p.Total__c;
             op.Remarks__c = p.Remarks__c;             
             /*op.quantity__c=p.Quantity__c;*/
            
             System.debug('-------------------> Order Products are Ids'+op);
             oplist.add(op);                               
        }
        }
        }        
        catch(Exception e)
            {
            system.debug(e);
            }
        if(oplist.Size()>0)
        {
            insert oplist;
        }
      PageReference reference=new PageReference('/'+Apexpages.CurrentPage().getParameters().get('Id'));
        
        return reference;
       }
      
}
Pankaj_GanwaniPankaj_Ganwani
Hi,

Formula and Roll up summary fields are read only. We cannot assign values in them. Please remove the reference of the assignment from your code. The formula field will automatically be calculated once the record will be saved.
Naveen KvpNaveen Kvp
Thanks for your Answer Pankaj..