You need to sign in to do that
Don't have an account?
vinod fnu
how to get fields from a list and compare it to the list other custom object
i have a scenario .I have a custom object party having fields 'related contact' and 'related companies'.
These fields are lookup to Contact Object and companies object.
each party record will have a related contact and related companies value.
I have a custom object named invoices .
For all companies we will have 1 invoices record.
on invoices object i want the list of all contacts in fields user 1 ,user 2 ,user 3
example
Record PARTY -1 james jo acme ltd
Party -2 marc acme ltd
party 3 lily pvd ltd
party 4 james jo amx ltd
Party 5 silly amx ltd
for record invoice with name acme ltd.
user 1=james jo (auto poulated by apex trigger or formulae)
user 2 = marc (auto poulated by apex trigger or formulae)
for record invoice with name amx ltd.
user 1=james jo (auto poulated by apex trigger or formulae)
user 2 = silly (auto poulated by apex trigger or formulae)
These fields are lookup to Contact Object and companies object.
each party record will have a related contact and related companies value.
I have a custom object named invoices .
For all companies we will have 1 invoices record.
on invoices object i want the list of all contacts in fields user 1 ,user 2 ,user 3
example
Record PARTY -1 james jo acme ltd
Party -2 marc acme ltd
party 3 lily pvd ltd
party 4 james jo amx ltd
Party 5 silly amx ltd
for record invoice with name acme ltd.
user 1=james jo (auto poulated by apex trigger or formulae)
user 2 = marc (auto poulated by apex trigger or formulae)
for record invoice with name amx ltd.
user 1=james jo (auto poulated by apex trigger or formulae)
user 2 = silly (auto poulated by apex trigger or formulae)
With the help of Map & Set, it's easily achievable.
Map<Id, List<Id>> accountIdToPartyContactIds = new Map<Id, List<Id>>(); //Populate the values from the party object to the map defined and Make sure you are removing the duplicates (List may contain duplicates)
//Id (Key) = Account Id; List<Id> (Values) = Contains all the Contact Id's from the party that are related to the specific account;
for (Invoice this|nv : invoiceList) {
if(accountIdToPartyContactIds.get(thisInv.Account__c) != null) {
thisInv.User1__c = thisInv.User1__c == null && accountIdToPartyContactIds.get(thisInv.Account__c).size() > 0 ? accountIdToPartyContactIds.get(thisInv.Account__c)[0] : thisInv.User1__c;
accountIdToPartyContactIds.get(thisInv.Account__c).remove(thisInv.User1__c); //Remove the Mapped Contact Id from set
thisInv.User2__c = thisInv.User2__c == null && accountIdToPartyContactIds.get(thisInv.Account__c).size() > 0 ? accountIdToPartyContactIds.get(thisInv.Account__c)[0] : thisInv.User2__c;
accountIdToPartyContactIds.get(thisInv.Account__c).remove(thisInv.User2__c); //Remove the Mapped Contact Id from set
}
}
//Above is just a sample code, but the logic should work
Party1 jole actimes
party2 merr ptmt
party 3 jole ltmt
part 4 aunt ltmt
if i prepare a list and remo0ve duplicates.I will miss out jole as a seprate for ltmt will not be in the added .however we will have ltmt in the list since it will come for aunt.
I hope this helps!!