You need to sign in to do that
Don't have an account?
Sujit Karande
Fetch related list records associated with Opportunity
I have related list called "Approvers" in opportunity object.
And I created few dummy records in approvers.
I am trying to fetch all those related list record associated with opportunity in apex trigger. As I wannted to assign values to the picklist field in realted list depend on Oppotunity pickist field value
For eg : Select all approvers where opportunity id="some-id";
Any suggestion would be really appreciated.
And I created few dummy records in approvers.
I am trying to fetch all those related list record associated with opportunity in apex trigger. As I wannted to assign values to the picklist field in realted list depend on Oppotunity pickist field value
For eg : Select all approvers where opportunity id="some-id";
Any suggestion would be really appreciated.
May I suggest you please refer the below link for reference.
- https://developer.salesforce.com/forums/?id=906F00000008ob4IAA
- https://stackoverflow.com/questions/18320047/dynamically-fetch-all-the-related-lists-for-an-object-for-eg-account
hope it helps.Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Rahul Kumar
I assume you have a lookup to opportunity from approver object
Trigger OppTrigger on Opportunity(after Update)
{
List<Approver__c> approvers=[select id,opportunityId from approver__c where id in:Trigger.new limit 50000];
Map<Id,List<Approver__c>> allApproverForOpportunity=new Map<Id,List<Approver__c>>();
For(Approver__c opp : approvers)
{
if(allApproverForOpportunity.isEmpty()==false)
{
List<Approver__c> listOfApprover;
if(allApproverForOpportunity.containsKey(opp.opportunityId))
listOfApprover=allApproverForOpportunity.get(opp.opportunityId);
else
listOfApprover=new List<Approver__c>(opp);
allApproverForOpportunity.put(opp.opportunityId,listOfApprover);
}
else
{
List<Approver__c> listOfApprover=new List<Approver__c>(opp);
allApproverForOpportunity.put(opp.opportunityId,listOfApprover);
}
}
}
// the map allApproverForOpportunity will contain all the opportunity id and its related list of approver
Let me know if you need further help
Thanks and Regards,
Shiva RV
Use a sub query as shown below. Replace Approvers__r with relavant child relationship name.
[Select Id, (Select Id from Approvers__r) from Id IN : Trigger.New]
Mark it as best answer if this is what you are looking for.