You need to sign in to do that
Don't have an account?
Nitish Pisal
I am trying to get list of unique values of a field (Store__r.region__c) on custom object which has lookup on lead object
I want to get all unique values of Store__c, so that I can use it to querry my store object later (I can't use group by here). My query looks like
Thanks
List<lead> listLead = [ SELECT Store__c FROM Lead WHERE status = 'Eligible']; Set<lead> random2 = new Set<lead>(); random2.addAll(listLead); System.debug(random2);The problem here is I am getting result for random2 as follows. I only want a set which has Store__c and not Id and RecordTypeId for lead
Lead: {Store__c=a0O1F000000R39cUAC, Id=00Q1F000002I6FFUA0, RecordTypeId=0121F000000B25UQAS}, Lead:{Store__c=a0O1F000000R4xqUAC, Id=00Q1F000002IBziUAG, RecordTypeId=0121F000000B25UQAS}}Also, my next question is : how do I use this Set to query the Store__c object to get all unique Regions__c. (How do I iterate the list of stores in soql query) e.g select region__c from Store__c where id= set of retrieved Store ids in previous query . Also, how efficient would it be?
Thanks
If this solves your problem, please mark this as BEST ANSWER
All Answers
If you just want to store the IDs of related Store__c records then you can do something like this:
And for the second part, once you get the list of IDs, you can write a qeury like this:
Regards,
Narender
Please mark a best answer if my answer helped you, so that others with similar problem can benefit from this post.
Thanks
Change filed/object Api names if required. Correct syntax error, if any
If this solves your problem, please mark this as BEST ANSWER
Hi Mritzi,
can I return the map to lightning component which has picklist to display the region names we fetched ? If not then I will have to return list of regions :(
If this solves your problem, please mark this as BEST ANSWER