You need to sign in to do that
Don't have an account?
Juan Miguel Francia
Need Help to finish my 1st afterInsert Trigger Handler
So what I need to do is
1st.) Get the newly created MatterID
2nd.) Query newly created OpportunityAccount for where OpportunityId = Matter__c.Project_Name__c (OpptyId)
3rd.) Get List based on Query.
4th.) Make List listOfMatterAccounts.
5th.) insert the data to a for loop.
Can you please help me finish my code. I created a something but I feel like it is not the right way to do it.
This is the original pseudo code given to me.
1st.) Get the newly created MatterID
2nd.) Query newly created OpportunityAccount for where OpportunityId = Matter__c.Project_Name__c (OpptyId)
3rd.) Get List based on Query.
4th.) Make List listOfMatterAccounts.
5th.) insert the data to a for loop.
Can you please help me finish my code. I created a something but I feel like it is not the right way to do it.
This is the original pseudo code given to me.
Add Related Vendor records to the Opportunity. Create New Matter from Opportunity [New Matter]... Make selections on Matter edit page.... Save. PB or afterInsert Trigger Handler gets Opportunity Id from Save event. ----Start Code Here---- Get new id for Matter.... <new matter id> Query newly created OpportunityAccount for where OpportunityId = Matter__c.Project_Name__c (OpptyId) Get List<Account> based on Query. Make List<MatterAccount__c> listOfMatterAccounts. for(Account a : listofOpportunityAccounts) { MatterAccount__c ma = new MatterAccount(); ma.matterid = <new matter id> ma.accountid = a.id ma.opportunityid = ma.Matter__c.Project_Name__c } listofMatterAccounts.insert(ma);
This is my code so far.
public static void RelatedVendor(){ //get new MatterID ID RecordID; List<Matter__c> listMatter = new List<Matter__c>(); List<OpportunityAccount__c> opporAccList = [Select id, opportunity__c from OpportunityAccount__c where id in : Trigger.new]; List<MatterAccount__c> mattAccList = new List<MatterAccount__c>(); for(Matter__c m :(List<Matter__c>)Trigger.new){ RecordID = m.Id; for(OpportunityAccount__c oa :opporAccList){ oa.Opportunity__c = m.Project_Name__c; opporAccList.add(oa); } for(Account a : opporAccList){ MatterAccount__c ma = new MatterAccount__c(); ma.Matter__c = RecordID; ma.Vendor__c = a.ID; ma.Opportunity__c = m.Project_Name__c; mattAccList.add(ma); } insert mattAccList; } }
Trigger :
All Answers
Trigger :