[SalesForce] Quote CPQ – how to correctly create a Quote Line Group and relate Quote Lines (without lines editor)

I am trying to automatically created Quote Line Groups when a new CPQ Quote is created, based on some fields on the Opportunity products.
But I fail.

In a trigger on SBQQ__QuoteLine__c I group the quote lines into sensible groups, and then create the group itself:

SBQQ__QuoteLineGroup__c cpqQLG = new SBQQ__QuoteLineGroup__c (SBQQ__Quote__c = myQuoteId, 
    SBQQ__SubscriptionTerm__c = 48,
    SBQQ__Account__c =  myAccountId,
    Name = 'Group  1',
    SBQQ__Number__c = 1
);
insert cpqQLG;

After (only) that, the Quote Lines editor works fine. It doesn't show any group, but all the quote lines.

The group is visible on the Quote record itself – all as expected.

In the next step my code then updates SBQQ__Group__c on the quote lines. If I now open the Quote Lines editor, it gets stuck loading and throws a javascript error on the console

TypeError: this.groupsByKey[y.parentGroupKey] is undefined   QuoteModel.js:73:3

On the Quote Line Group record I can correctly see the Quote Line in the related tab.

To rule out that the rest of my code is suboptimal, I did the reparenting of the Quote lines manually, meaning I edited the record of the quote line, put "Group 1" into the field "Group" and saved this. => Same error

If I have 2 Groups on a Quote, I can move a Quote Line from one group to the other by editing the "Group" field. For example, I let the code create my group first, then go into the lines editor, create another group, then edit the Quote Line record and change "Group" to my programmatically created groupd.

Same behaviour with my code, and I am now out of ideas.

Is there anything that needs to be done except for create a group and and set the Group-field on Quote Line to the newly created group?

I have compared Quote Lines / Quote Line Groups created via the lines editor and my way, but there is no difference (except for changed IDs and timestamps of course).

Or is there a more CPQ-compliant way to achieve what I want to do – automatically create groups and sort quote lines into them?

Or is CPQ storing some information outside of the SF database – has anyone exerience with successfully moving CPQ Orders to another org?

Best Answer

Thanks to the Salesforce support I have the answer now.

CPQ only expects either all quote lines to be grouped or none. If the lines are grouped, SBQQ__Quote__c.SBQQ__LineItemsGrouped__c needs to be set to true, otherwise the Quote Lines editor will hang with the error I cited.

Related Topic