top of page

Indexation (upgrade prices at once)

Introduction

I want to increase a price of all my contract from a market, how to do it?


Custom field you need

In contract



Apex



public class ContractsIndexation {
    public class QuoteLineModel {
    	public SBQQ__QuoteLine__c record;
	}

    public class QuoteModel {
    	public SBQQ__Quote__c record;
    	public QuoteLineModel[] lineItems;
	}

    @InvocableMethod(
        label='IndexationContracts'
        description='Check quotelines for products linked to specific Contract IDs.'
        category='Account'
    )
    public static List<List<String>> ContractsIndexationM(List<String> IndexTypes) {
        List<String> quoteIdsList = new List<String>();

        // Query all contracts with IndexationType__c IN :IndexTypes
        List<Contract> contracts = [SELECT Id FROM Contract WHERE TypeIndexation__c IN :IndexTypes];

        for (Contract co : contracts) {
            quoteIdsList.add(QLUpdater(co.Id));
        }

        List<List<String>> result = new List<List<String>>();
        result.add(quoteIdsList);
        return result;
    }

    public with sharing class AmendedContract {
        public QuoteModel load(String contractId, String context) {
            try {
                String quoteJSON = SBQQ.ServiceRouter.load('SBQQ.ContractManipulationAPI.ContractAmender', contractId, context);
                return (QuoteModel) JSON.deserialize(quoteJSON, QuoteModel.class);
            } catch (Exception e) {
                // Handle any exceptions here
                return null;
            }
        }
    }

    public with sharing class AmendContext {
        public Boolean returnOnlyQuoteId;
    }

    public static String createAmendment(String contractId) {
        AmendContext context = new AmendContext();
        context.returnOnlyQuoteId = false;
        String contextJson = JSON.serialize(context);

        AmendedContract amender = new AmendedContract();
        QuoteModel quote = amender.load(contractId, contextJson);

        if (quote != null) {
            SBQQ__Quote__c quoteRec = quote.record;
            return (String) quoteRec.Id;
        } else {
            // Handle the case where loading the QuoteModel failed
            return null;
        }
    }

    public static String QLUpdater(String contractId) {
        return createAmendment(contractId);
    }

    public void CIndexation(String IndexType) {
        List<String> quoteIds = new List<String>();

        // Query all contracts with IndexationType__c = :IndexType
        List<Contract> contracts = [SELECT Id FROM Contract WHERE TypeIndexation__c  = :IndexType];


        for (Contract co : contracts) {
            quoteIds.add(QLUpdater(co.Id));
        }

        system.debug('New Quotes IDs: ' + quoteIds);
    }
}

Flow













Result

when you finished to implement this and add a button on the list view button in contract like this:



Here the video:



0 views0 comments

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page