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
Nevin O'Regan 3Nevin O'Regan 3 

Trigger To Update Field On OpportunityLineItem From OpportunityLineItemSchedule

Hi guys,

I have custom formula fields on the OpportunityLineItemSchedule object which display a month based on the month the scheduled date falls within. 

I have created 12 custom fields on the OppLine object, each labeled one of the months of the year. I need a way of rolling up the Quantity of the the related schedules to the corresponding custom fields on the OppLine. 

Has anyone created anything similar in the past?
Best Answer chosen by Nevin O'Regan 3
Piyush Gautam 6Piyush Gautam 6
Hi Nevin O'Regan,

Please check the data type of the fields, there is a possibility the Fields named as 'January__c' and 'Feburary__c' are a string and Month__c is a decimal type.

Make both the type same for the fields
else try this:
January__c = string.ValueOf(sch.Month__c)


If helps marked as solved.
Thanks

All Answers

Nevin O'Regan 3Nevin O'Regan 3
I have had a go and I think I'm almost there. However, I'm getting the following error

"Illegal assignment from String to Decimal"

Here is my trigger

trigger MatchingMontsOnOppLineItem on OpportunityLineItemSchedule (after insert, after update) {
List<OpportunityLineItem> oli = new List<OpportunityLineItem>();
    for (OpportunityLineItemSchedule sch : trigger.new)
    {
        if (sch.Month__c != null)
        {
            oli.add(new OpportunityLineItem(Id = sch.OpportunityLineItemId, January__c = sch.Month__c));
            oli.add(new OpportunityLineItem(Id = sch.OpportunityLineItemId, February__c = sch.Month__c));
        }
        else
        {
            oli.add(new OpportunityLineItem(Id = sch.OpportunityLineItemId, January__c = null));
            oli.add(new OpportunityLineItem(Id = sch.OpportunityLineItemId, February__c = null));
        }
    }
    if (oli.size() > 0)
    {
        update oli;
    }
}
Piyush Gautam 6Piyush Gautam 6
Hi Nevin O'Regan,

Please check the data type of the fields, there is a possibility the Fields named as 'January__c' and 'Feburary__c' are a string and Month__c is a decimal type.

Make both the type same for the fields
else try this:
January__c = string.ValueOf(sch.Month__c)


If helps marked as solved.
Thanks
This was selected as the best answer