private void marcarCSP(List<Cot_ServicioProducto__c> lista, Boolean isDel){
Set<Id> idsDel=new Set<Id>();
Set<Id> idsCps=new Set<Id>();
Set<Id> idsCsp=new Set<Id>();
for(Cot_ServicioProducto__c cspr : lista){
idsCps.add(cspr.Cot_PlanServicio__c);
idsDel.add(cspr.Id);
}
List<Cot_PlanServicio__c> cps = [SELECT Cot_SitioPlan__c FROM Cot_PlanServicio__c WHERE Id IN :idsCps];
for(Cot_PlanServicio__c ps : cps){
if(ps.Cot_SitioPlan__c!=null)
idsCsp.add(ps.Cot_SitioPlan__c);
}
if(idsCsp.size()>0){
Set<Id> idsCspT=new Set<Id>();
List<Cot_ServicioProducto__c> elim;
if(isDel)
elim=[SELECT Cot_PlanServicio__r.Cot_SitioPlan__c FROM Cot_ServicioProducto__c WHERE Cot_PlanServicio__r.Cot_SitioPlan__c IN :idsCsp AND DP_Producto__r.EsTercero__c=true AND Id NOT IN :idsDel];
else
elim=[SELECT Cot_PlanServicio__r.Cot_SitioPlan__c FROM Cot_ServicioProducto__c WHERE Cot_PlanServicio__r.Cot_SitioPlan__c IN :idsCsp AND DP_Producto__r.EsTercero__c=true];
for(Cot_ServicioProducto__c ter : elim){
idsCspT.add(ter.Cot_PlanServicio__r.Cot_SitioPlan__c);
}
List<Cot_SitioPlan__c> cspUpdt=[SELECT Id,TieneTercero__c FROM Cot_SitioPlan__c WHERE Id IN :idsCsp];
for(Cot_SitioPlan__c csp: cspUpdt){
if(idsCspT.contains(csp.Id))
csp.TieneTercero__c=true;
else
csp.TieneTercero__c=false;
}
update cspUpdt;
}
}
@Keiji Otsubo There is a trigger.
public void run() {
if(!validateRun()) return;
addToLoopCount();
if(this.context == TriggerContext.BEFORE_INSERT) {
this.beforeInsert();
} else if(this.context == TriggerContext.BEFORE_UPDATE) {
this.beforeUpdate();
} else if(this.context == TriggerContext.BEFORE_DELETE) {
this.beforeDelete();
} else if(this.context == TriggerContext.AFTER_INSERT) {
this.afterInsert();
} else if(this.context == TriggerContext.AFTER_UPDATE) {
this.afterUpdate();
} else if(this.context == TriggerContext.AFTER_DELETE) {
this.afterDelete();
} else if(this.context == TriggerContext.AFTER_UNDELETE) {
this.afterUndelete();
}
}