You need to sign in to do that
Don't have an account?
anil87
Trigger on opportunity object
Hi Everyone ,
I want to a trigger on the Oppotunity object, which would capture the Opp Products into the Fullfillment Parts object (custom object). This should happen when the opp status is changed to "Approved"( custom field on opportunity) my custom object has a master detail relation with opportunity..help me in this regard..how i can proceed
Hi,
You need to write a trigger on the Opportunity object.
In the trigger using .old &.new values check whether status is changed to "Approved" or not.
1) For all such oppty records define a list & store them in a List.
2) define a list of Fullfillment object (outside for loop.
3) in a for loop : loop through all the oppty records
4) define a local Fullfillment object record within for loop & store the product details in that .
5) add the local Fullfillment record in the FullfillmentList defined outside of the for loop.
6) outside the for loop insert those Fullfillmentlist records.
You can define a service class as well and call that service class from your trigger by passing .old &.new values and do the calculation/manipulation in the service class.
Hi Rahul
Thanks for replying,i written the trigger but got an error could please fix it
this is the error
System.StringException: Invalid id: DW Test: Trigger.capturingoppproducts: line 26, column 1
trigger capturingoppproducts on Opportunity (after insert,after update) {
List<OpportunityLineItem> oli=new List<OpportunityLineItem>();
List<product2> pro=new List<product2>();
List<FullFillment_Part__c> ffp=new List<FullFillment_Part__c>();
Set<ID> prodids =new Set<ID>();
for(Opportunity o:trigger.new){
if(o.Design_Win_Approval_Process__c=='Approved')
{
oli=[select PricebookEntryId,PricebookEntry.Product2Id from OpportunityLineItem
where Opportunityid =: o.id];
}
for(OpportunityLineItem ol:oli){
prodids.add(ol.PricebookEntry.Product2Id);
}
System.Debug('Product Ids are '+prodids);
pro=[select id,name,ProductCode from Product2
where id in: prodids];
for(product2 p:pro){
FullFillment_Part__c fp=new FullFillment_Part__c();
fp.Opportunity__c=o.name; //
Error linefp.product__c=p.name;
ffp.add(fp);
}
insert ffp;
}
}
Anil,
Can you change line 26 from
fp.Opportunity__c=o.name;
To
fp.Opportunity__c=o.id;
Hi vinit
yeah i got it thanks for replying along with opportunity__c and product__c i have two more fields value1,value2 in product i need to copy those two fields into val1,val2 of fullfillment part object but val1 should be readonly ,val2 is editable how can i make this.