0

I hope you are well, I would like to ask for your help with something that you have in mind and I can not do it haha

If I have two different object record lists and the first record list has a lookup field towards the second object and it is worth mentioning that the lists are the same size.

How can I assign a record from list 2 to each record from list 1?

These are my two lists:

rv = [Select Id, Name, Meta__c, CancellationDateRV__c, AccumulationGroupRV__c 
              From Resumen_de_Ventas__c
              Where Oportunidad__c in: opps];

mts = [Select Id, Name, AccumulationGroup__c, Fecha_de_inicio__c, Fecha_fin__c, Usuario__c
                   from Metas__c 
                   where Fecha_de_inicio__c <=: CancellationDate and Fecha_fin__c >=: CancellationDate and AccumulationGroup__c =:accumulationGroup];

The situation or panorama of the operation is that when an opportunity is canceled, the records of "Summary_de_ventas__c", in the field "Meta__c" change to the goal that corresponds to the cancellation date, this cancellation date is formulated in the sale summary from the opportunity.

How can I achieve this? I really appreciate your support.

2
  • the Resumen_de_Ventas__c.Meta__c is lookup to the Metas__c object?
    – Damecek
    Aug 3, 2021 at 17:06
  • @Damecek it is master-detail, but it is configured so that it can be modified, and it is from Metas__c Aug 3, 2021 at 17:20

1 Answer 1

0

As you stated that the Resumen_de_Ventas__c.Meta__c is lookup to the Metas__c object, you could avoid all of this with this simple query.

Select Id, Name, Meta__c, CancellationDateRV__c, AccumulationGroupRV__c,
    Meta__r.Id, Meta__r.Name, Meta__r.AccumulationGroup__c, Meta__r.Fecha_de_inicio__c, Meta__r.Fecha_fin__c, Meta__r.Usuario__c
              From Resumen_de_Ventas__c
              Where Oportunidad__c in: opps AND
    Meta__r.Fecha_de_inicio__c <=: CancellationDate and Meta__r.Fecha_fin__c >=: CancellationDate and Meta__r.AccumulationGroup__c =:accumulationGroup

This would give you the intersection of the two lists above.

Or you could go the other way around and have all Metas__c and some of them will have the related Resume_de_Ventas__c like so.

Select Id, Name, AccumulationGroup__c, Fecha_de_inicio__c, Fecha_fin__c, Usuario__c, (Select Id, Name, Meta__c, CancellationDateRV__c, AccumulationGroupRV__c 
              From **Resumen_de_Ventas__r**
              Where Oportunidad__c in: opps)
                   from Metas__c 
                   where Fecha_de_inicio__c <=: CancellationDate and Fecha_fin__c >=: CancellationDate and AccumulationGroup__c =:accumulationGroup

Pls be aware that i am only guessing the relation name above **Resumen_de_Ventas__r** so this probably will need some adjustments.

1
  • Thank you so much! With the second option I obtain the Metas__c that would correspond to the Resumen_de_vetnas__c ... How can I assign those Metas__c to each Resumen_de_ventas__c that were found in the opportunity? In the opportunity there are always 4 Resumenes_de_ventas__c and there should always be 4 Metas__c that correspond to the cancellation date Aug 3, 2021 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.