You need to sign in to do that
Don't have an account?
sean.gorman@ipc.com
Trigger to create new Opp from Custom Object - need Opp ID in Custom Object
Hi,
I have a new custom object stores Opportunity related data which can be used to create a new opportunity.
I cannot think of a way to store the new OPPID in the relavent record.
trigger Process_IB2U on IB2U__c (Before Update) { set<id> IBIds = new set<id>(); map<id,id> mapIBtoOpp = new map<id,id>(); list<IB2U__c> newIB2U = new list<IB2U__c>(); set<IB2U__c> IBs_toUpdate = new set<IB2U__c>(); list<Opportunity> Opp_forInsert = new list<Opportunity>(); Pricebook2[] priceBook = [Select p.Name, p.Id From Pricebook2 p where p.Name = 'Trading Price Book']; for(IB2U__c IB: trigger.new) { if(IB.Convert_to_Opportunity__c == TRUE) { IBs_toUpdate.add(IB); Opportunity oppty = new Opportunity (StageName = 'Price / Quote', Opp_Probability__c = '60', Name = 'IB2U Converted Opp', Estimated_Revenue_Amount__c = IB.Estimated_Revenue_Amount__c, CloseDate = IB.Estimated_Contract_Date__c, Amount = 200, AccountId = IB.Account__c, CurrencyIsoCode = IB.CurrencyIsoCode, Unigy__c = TRUE, Site_Name__c = IB.Account_Site__c, Distributor__c = IB.Distributor__c, Pricebook2Id = priceBook[0].Id, Incumbent__c = IB.Incumbant__c ); Opp_forInsert.add(oppty); } } insert Opp_forInsert; for(Opportunity Oppt: Opp_forInsert) { // this does not work as IB is out of context IB.Opportunity__c = Oppt.id; } // Again - will not work update IB; }
I have a couple of SETs and MAPs that are not currently used... I was playing with them to get the ID of the IB and OPP together - but I cannot without requerying the Opportunity table with a related list of IB.IDs and saving the related IB on the Opportunity.
You can do this by creating a map with the Id of the IB that is associated with the opportunity being inserted.
Try something like this:
All Answers
You can do this by creating a map with the Id of the IB that is associated with the opportunity being inserted.
Try something like this: