Skip to main content

public static String guardamodelado (SitioModelado sitioModelado) {

Map<String, String> mCantidadPlanes = new Map<String, String>();

List<Cot_Sitio__c> listCS = [SELECT Id, Cotizacion__c,Sitio__c,Sitio__r.Plaza__c FROM Cot_Sitio__c WHERE Id=:sitioModelado.Cot_Sitio.Id];

Set<Id> setIdsCSP = new Set<Id>();

Set<String> setIdsProductos = new Set<String>();

Map<String,AdicionalProd> mapProductos = new Map<String,AdicionalProd>();

Map<String,String> mapCSPservicio = new Map<String,String>();

Set<Id> setIdsServicios = new Set<Id>();

Map<String,AdicionalServ> mapServicios = new Map<String,AdicionalServ>();

Set<Id> setIdsPromo = new Set<Id>();

Map<String,AdicionalPromo> mapPromo = new Map<String,AdicionalPromo>();

for(Plan itemPlan :sitioModelado.Planes){

mCantidadPlanes.put(itemPlan.DP_Plan.Id,''+itemPlan.Cantidad);

}

Map<String, Object> result = COT_Cotizador3ModeladoController.agregarPlanesNuevo(listCS[0].Cotizacion__c,listCS[0].Sitio__c,mCantidadPlanes);

COT_SitioWrapper cotSitioWrapper = (COT_SitioWrapper)result.get('cotSitioWrapper');

for(COT_PlanWrapper ck:cotSitioWrapper.listPlanWrapper){

String dpCSP = ck.cotPlan.DP_Plan__r.Id+'-'+ck.cotPlan.Id;

setIdsCSP.add(ck.cotPlan.Id);

mapCSPservicio.put(ck.cotPlan.Id,dpCSP);

}

if(sitioModelado.CuentaFactura != NULL){

Cot_SitioPlan__c nuevoCSP = new Cot_SitioPlan__c();

for(COT_PlanWrapper cspPV : cotSitioWrapper.listPlanWrapper){

if(cspPV.cotPlan.CuentaFactura__c == NULL){

nuevoCSP.Id = cspPV.cotPlan.Id;

nuevoCSP.CuentaFactura__c = sitioModelado.CuentaFactura.Id;

}

}

if(nuevoCSP.CuentaFactura__c != NULL){

update nuevoCSP;

}

}

String plz=listCS[0].Sitio__r.Plaza__c;

for(Plan itemPlan :sitioModelado.Planes){

for(AdicionalProd itemProd :itemPlan.Productos){

if(itemProd.DP_ServicioProducto.Plaza__c==null || itemProd.DP_ServicioProducto.Plaza__c.contains(plz)){

setIdsProductos.add(itemProd.DP_ServicioProducto.Id);

mapProductos.put(itemProd.DP_ServicioProducto.Id,itemProd);

}

}

for(AdicionalServ itemServ :itemPlan.Servicios){

if(itemServ.DP_PlanServicio.Plaza__c==null || itemServ.DP_PlanServicio.Plaza__c.contains(plz)){

setIdsServicios.add(itemServ.DP_PlanServicio.Id);

mapServicios.put(itemServ.DP_PlanServicio.Id,itemServ);

}

}

for(AdicionalPromo itemProm :itemPlan.Promociones){

if(itemProm.Cantidad>0 && (itemProm.DP_PromocionPlan.Plaza__c==null || itemProm.DP_PromocionPlan.Plaza__c.contains(plz))){

setIdsPromo.add(itemProm.DP_PromocionPlan.Id);

mapPromo.put(itemProm.DP_PromocionPlan.Id,itemProm);

}

}

}

if(setIdsProductos.size()>0){

agregarProductosAdicionales(setIdsCSP,setIdsProductos,mapProductos);

}

if(setIdsServicios.size()>0){

agregarServiciosAdicionales(setIdsCSP,setIdsServicios,mapServicios,mapCSPservicio);

}

if(setIdsPromo.size()>0){

agregarPromocion(setIdsCSP,setIdsPromo,mapPromo,mapCSPservicio);

}

return 'Guardado Exitosamente';

}

 

 
2 réponses
  1. 4 janv. 2021, 23:10
    Hi Cristino,

     

    I suspect this method is getting called multiple times in a transaction. 

     

    Governor limits are for a particular transaction which can consist of Process Builder/Workflow Rule/Flows and triggers. You need to analyze Debug log to find out which process/trigger is utilizing most of the SOQL limits. 

     

    You may refer below article for best practices to avoid SOQL governer limits:

     

    https://help.salesforce.com/articleView?id=000331875&type=1&mode=1 (https://help.salesforce.com/articleView?id=000331875&type=1&mode=1)
0/9000