I'm new to coding and I need help in modifying the apex trigger below to the correct one. Can you also help me in creating a test class for this? Thank you so much!
trigger UpdateLadderedFields on OpportunityLineItem (before insert, before update)
{
for (OpportunityLineItem oli: Trigger.new)
{
string OppprodSKUID;
OppprodSKUID = oli.SKU_ID__c.substring(0,15);
If(oli.Q4_Laddered__c != null)
{
List<Ladders_RDP__c> lr = [SELECT ID, SKU_ID__c, Total_Laddered__c, OE_Qtr__c
FROM Ladders_RDP__c WHERE SKU_ID__c = :OppprodSKUID];
for(Ladders_RDP__c l: lr)
{
If(l.OE_Qtr__c.contains('Q4')) {
oli.Q4_Laddered__c = l.Total_Laddered__c;}
else If(l.OE_Qtr__c.contains('Q3')){
oli.Q3_Laddered__c = l.Total_Laddered__c;}
else If(l.OE_Qtr__c.contains('Q2')){
oli.Q2_Laddered__c = l.Total_Laddered__c;}
else IF(l.OE_Qtr__c.contains('Q1')){
oli.Q1_Laddered__c = l.Total_Laddered__c;}
}
}
}
}