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
DIVAKAR BABU 15DIVAKAR BABU 15 

opportunity Line item have 2 fields one is quantity and another is discount .but my question is can we autopopulate discount field based on quatity

suppose quantity is more than 10 
discount wil be 20%

quantity is more than 20 
discount will be 30%
AnudeepAnudeep (Salesforce Developers) 
Have a tried creating a simple trigger on OpportunityLineItem
 
trigger update_discount on OpportunityLineItem (after insert, after update) 
       {
             List <OpportunityLineItem> oliToInsert = new List <OpportunityLineItem> (); 
                for (OpportunityLineItem m : Trigger.new) 
                   { 
                      OpportunityLineItem oli = new OpportunityLineItem (); 
                      if(oli.quantity >10) {
                      oli.discount = 0.02 //set 20% as value
                      }else if (oli.quantity >20) {
                      oli.discount = 0.03 // set 30% as value
                      }
                      oliToInsert.add(o);  
                   }
                       try
                         { 
                               insert oliToInsert; 
                         } 
                         catch (system.Dmlexception e)
                         {
                               system.debug (e);
                         }
             }

NOTE: The code provided is an example. You'll need to review and make modifications for your organization.

Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!
DIVAKAR BABU 15DIVAKAR BABU 15
Trigger Not working 
DIVAKAR BABU 15DIVAKAR BABU 15
Can you give formula for workflow action like
if(opportunitylineitem.qty >10){
discount=10%
}