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
sagar077sagar077 

Write an apex trigger for update custom field Details_oF_Product__c (text area datatype) . after insert this events want to use. On the Opportunity object, there is a releted list name as Products (Standard) it will take recor

Write an apex trigger for update custom field Details_oF_Product__c (text area datatype) .
after insert, after update , after delete this events want to use.
On the Opportunity object, there is a releted list name as Products (Standard) it will take record data from there and show on custom fields name as Details_oF_Product__c (text area datatype).
Three fields should be show name as Product Code, List Price, Quantity.

Plz help me in this trigger i am new in trigger.
thanks

The result will show on the custom field that is  Details_oF_Product__c (text area datatype)
----------------------------------------
----------------------------------------
Product Code : beds 
List Price :200
Quantity : 1 
----------------------------------------
----------------------------------------User-added imageUser-added image
 
ShirishaShirisha (Salesforce Developers) 
Hi Sagar,

Greetings!

Unfortunately,we do not have the exact code as per your requirement.However,here are the steps to create the trigger:

If the field Details_oF_Product__c is on Opportunity and you need to get and store the values from child record.

Please refer the sample code to update the parent record from the Child record.

https://salesforce.stackexchange.com/questions/23338/trigger-to-update-parent-object-value-with-child-value

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
sagar077sagar077
please help me in this code for after update , before delete events
CODE-

trigger OpportunityProductt on OpportunityLineItem (after insert,after update)
{           
    Set<Id> oppid = New Set<Id> ();
    for(OpportunityLineItem pr :Trigger.New)
        {
          system.debug('my line'+pr.OpportunityId);
          oppid.add(pr.OpportunityId);
           }
    List <Opportunity> AllOpport = [Select Id ,Details_oF_Product__c, (Select ProductCode , ListPrice , Quantity From OpportunityLineItems) From Opportunity Where Id IN : oppid ];
    system.debug('my linee'+ AllOpport);
   
    Set <Opportunity> opUpdate = New Set<Opportunity> ();
    for(Opportunity ops:AllOpport)
      {
         system.debug('my lines'+  ops);  
         for(OpportunityLineItem OLine:ops.OpportunityLineItems)
      {
          system.debug('my liness'+ OLine);        
          if(trigger.isinsert)
          {      
          if(ops.Details_oF_Product__c != null && ops.Details_oF_Product__c.countMatches( 'ProductCode =' + OLine.ProductCode  + ',' + 'ListPrice='+ OLine.ListPrice + ',' + 'Quantity='+ OLine.Quantity)==0)
          {
              ops.Details_oF_Product__c += '\n' + 'ProductCode =' + OLine.ProductCode  + ',' + 'ListPrice='+ OLine.ListPrice + ',' + 'Quantity='+ OLine.Quantity +'\n';
          }
         
          else
              {
              ops.Details_oF_Product__c = 'ProductCode =' + OLine.ProductCode  + ',' + 'ListPrice='+ OLine.ListPrice + ',' + 'Quantity='+ OLine.Quantity ;
         }          
         }
          if(trigger.isupdate){
              ops.Details_oF_Product__c ='';
              if(ops.Details_oF_Product__c != null && ops.Details_oF_Product__c.countMatches( 'ProductCode =' + OLine.ProductCode  + ',' + 'ListPrice='+ OLine.ListPrice + ',' + 'Quantity='+ OLine.Quantity)==0)
          {
              ops.Details_oF_Product__c += '\n' + 'ProductCode =' + OLine.ProductCode  + ',' + 'ListPrice='+ OLine.ListPrice + ',' + 'Quantity='+ OLine.Quantity +'\n';
          }
         
          else
              {
              ops.Details_oF_Product__c = 'ProductCode =' + OLine.ProductCode  + ',' + 'ListPrice='+ OLine.ListPrice + ',' + 'Quantity='+ OLine.Quantity ;
         }   
             
          }
      }
          Update ops;
    }