I have a specific format of the Json that I save with opportunity and account values, as in the example below, but in the LINEAS section would depend on the number of products that have the opportunity, how could I do that?
req.setBody(
' "Negociación":'+'{'+
'"PorcentajeAumentoAnual": "' + SelOportunity.PAA__c +'",' +
'"PorcentajeAumentoAnual": "' + SelOportunity.Porcentaje_Aumento_Anual_Piso__c +'",' +
'"TipoNegociacion": "' + SelOportunity.Tipo_de_Renta__c +'",' +
' "Lineas":'+'['+
'{'+
/*'"RecordIdLinea": "' + SelProduct.Id +'",' +
'"Categoria": "' + SelProduct.Articulo__c +'",' +
'"Cantidad": "' + SelProduct.Quantity +'",' +
'"CAM": "' + SelProduct.Total_CAM__c +'",' +
'"PrecioUnitarioLocal": "' + SelProduct.Prorrateo__c +'"' +
'"PrecioTotalLinea": "' + SelProduct.Prorrateo__c +'",' +
'"IDLocal": "' + SelProduct.ProductCode +'",' +*/
'}' +
'],
)
With the following query I obtain the products related to the opportunity with the data that it would occupy, but that data would be assigned to the values of the LINEAS segment of the Json
Opportunity op = [SELECT id, (SELECT Id,Articulo__c,Quantity,Total_CAM__c,Prorrateo__c,ProductCode FROM opportunitylineitems)FROM opportunity WHERE Id =: OpportunityId];
How could you make the line part dynamic depending on the number of products of the opportunity?
Saludos!