For salesforce, I want to be able to update a quantity of quote lines in a amended quote.
The Setup
I am running the contract amender api to create a amended opportunity -> quote:
public with sharing class AmendedContract{
public QuoteModel load(String contractId, String context) {
String quoteJSON = SBQQ.ServiceRouter.load('SBQQ.ContractManipulationAPI.ContractAmender', contractId, context);
//system.debug('contract ID: ' contractId);
//system.debug('Quote Json: ' quoteJSON);
return (QuoteModel) JSON.deserialize(quoteJSON, QuoteModel.class);
}
}
public with sharing class AmendContext {
public Boolean returnOnlyQuoteId;
}
public String createAmendment(String cID)
{
system.debug('-----AMENDMENT CREATION STARTED-----');
AmendContext con1 = new AmendContext();
//system.debug('AMEND CONTEXT CON1: ' con1);
con1.returnOnlyQuoteId = false;
String contextJson = JSON.serialize(con1);
AmendedContract amender = new AmendedContract();
QuoteModel quote = amender.load(cID, contextJson);
//system.debug('ABUL-QUOTEMODEL: ' quote);
SBQQ__Quote__c quoteRec = quote.record;
String quoteId = (String) quoteRec.Id;
system.debug('Amended quote ID: ' quoteId);
return quoteId;
}
I was able to retrace the quote id of the amended quote (quoteId)
but the issues is what I need to do next.
What I need
I need to be able to take the quoteId
that was created from the amendment and update the quote line items to have a new quantity.
Is there a possibility to update the quote lines and change the quantity field?
CodePudding user response:
You can use SOQL
and DML
List<SBQQ__QuoteLine__c> qlList = new List<SBQQ__QuoteLine__c>();
// quoteId is the record id of SBQQ__Quote__c
for(SBQQ__QuoteLine__c ql:[SELECT id,SBQQ__Quantity__c FROM SBQQ__QuoteLine__c WHERE SBQQ__Quote__c = : quoteId]){
// Replace the below line with the logic in which qty needs to be updated
ql.SBQQ__Quantity__c = ql.SBQQ__Quantity__c 1;
qlList.add(ql);
}
UPDATE qlList;