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
LIM AI KHOONLIM AI KHOON 

data value too large: (value has been hidden)

Hi, I received this error
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger PullSoData caused an unexpected exception, contact your administrator: PullSoData: data changed by trigger for field Sales Order Information: data value too large: (value has been hidden)

I think it is because of this. May I know how to improve this code?
 
//Develop by Wan Nur Atiqah/CR_CRM088

trigger PullSoData on Payment_Term_Credit_Limit__c (before Insert, before update) {
    try{
        double myRinggit = 0;
        double CNYSing = 0;
        double EURODollar = 0;
        
        set<Id> lstId = new set<Id>();
        for(Payment_Term_Credit_Limit__c ob:trigger.new){
            if(ob.Name_of_Customer__c != null){
                lstId.add(ob.Name_of_Customer__c);
            }
        }
        list<Sales_Order__c> lstOb1 =[select Id, Requested_Delivery_Date__c, account__c, Account_SO_No__c,Po_No__c,Total_Qty_Pcs__c,Total_Amount_USD__c,Currency__c, name from Sales_Order__c where Account__c IN :lstId AND Status__c LIKE '%E0005%' and Billed__c=false order by CreatedDate ];
        for(Payment_Term_Credit_Limit__c ob2: trigger.new){
            
            ob2.Sales_Order_Information__c = '';
            ob2.Grand_Total__c = 0;
            ob2.Shipment_Value_SO__c = 0;
            ob2.Shipment_Value_SO_USD__c = 0;
            for(integer i=0; i<lstOb1.size(); i++){
                integer numbering = i+1;
                ob2.Sales_Order_Information__c += '<b>['+numbering+']</b>'+' <b>SO No.:</b> ' + lstOb1[i].name + ', <b>Request Delivery Date:</b> ' + lstOb1[i].Requested_Delivery_Date__c+', <b>Po. No:</b> '+lstOb1[i].Po_No__c+',<b> Total Quantity.pcs: </b>'+lstOb1[i].Total_Qty_Pcs__c+', <b> Total Amount. USD:</b> '+lstOb1[i].Total_Amount_USD__c+', <b>Currency: </b> ' + lstOb1[i].Currency__c + '<Br/>';
                ob2.Grand_Total__c = ob2.Grand_Total__c + lstOb1[i].Total_Amount_USD__c;
                
                if( lstOb1[i].Currency__c!='USD'){
                    ob2.Shipment_Value_SO__c = ob2.Shipment_Value_SO__c + lstOb1[i].Total_Amount_USD__c;
                }else{
                    ob2.Shipment_Value_SO_USD__c = ob2.Shipment_Value_SO_USD__c + lstOb1[i].Total_Amount_USD__c;
                }
            }
        }
        
    }catch(Exception e){
        system.debug('Got error::'+e);
    }
    
}

How to not have a query in for loop? 
 
PriyaPriya (Salesforce Developers) 
Hey LIM,

Kindly refer these link :-
https://help.formassembly.com/help/salesforce-error-data-value-too-large
https://help.salesforce.com/s/articleView?id=000353046&type=1

Thanks!