function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepak Pandey 13Deepak Pandey 13 

trigger example on opportunitylineitem

i wanna a code which is firring when opportunity has been created than opportunitylineitem also filled... using trigger
AshlekhAshlekh
Hi,

You can write a Trigger on Opportunity.
 
trigger OpportunityTrigger on Opportunity (after insert) 
{
	List<OpporutnityLineItem> newLineItem = new List<OpporutnityLineItem>();
	for(Opportunity opp : Trigger.new)
	{
		OpporutnityLineItem Oppitem = new OpporutnityLineItem();
        //You need to assign value all to required fields 
        Oppitem.opportunityId = opp.id;
        Oppitem.Quantity=1; 
        Oppitem.UnitPrice=50; 
        Oppitem.PriceBookEntryId = assign id; 
    	newLineItem.add(Oppitem);
	}
	
	if(newLineItem.size()>0)
		insert newLineItem;
		
}

-Thanks
Ashlekh Gera