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
Samantha StarlingSamantha Starling 

Custom button to send data from a custom object to Opportunity Product

Hi everyone...I am new to development and working on my first Apex Class to send information from a custom object called Production Details to the Opportunity Product and I am almost there! I need the FOR loop to be contingent on the Opportunity Product Number field on the Production Details matching the same field on the Opportunity Product (which is an auto number field) so that when the user inputs the same number that was generated on the creation of the Oppty Prod onto the Production Details and saves then clicks the "Send to Oppty Prod" button, the data will get sent. Can anyone take look and offer some help in getting this finished? Code below...

global class ProductionDetailConversion{
    webService
    static String copyProductionDetail(Id Production_DetailId){
        List<Production_Detail__c> lstProductionDetail =
            [
                SELECT 
                    Id, 
                    Shipping_Costs__c, 
                    Act_Postage_Total__c,
                    Per_Piece_Cost__c 
                    
                FROM 
             Production_Detail__c 
                WHERE 
                    Id = :ProductionDetailId
            ];
 
    
       List <OpportunityProductLineItem> lstOpportunityProductLineItem = new 

List<OpportunityProductLineItem>();
 
        for(Production_Detail__c Opportunity Product Number : OpportunityLineItem 

Opportunity Product Number){
              
                    lstOpportunityProductLineItem.add(
                        new OpportunityProductLineItem(
                            
                            Shipping_Costs__c = 

OpportunityLineItem.Shipping_Costs__c,
                            Act_Postage_Total__c = 

OpportunityLineItem.Postage_Costs__c,
                            Per_Piece_Cost__c = 

OpportunityLineItem.Per_Piece_Costs__c,
                       
                        )
                    );
               }     
      try{   
            INSERT lstOpportunityProductLineItem;
            return lstOpportunityProductLineItem[0].Id; 
        }
        catch (Exception ex){
            
            return('Error');
        } 
ShashankShashank (Salesforce Developers) 
Can you elaborate a little more on what you mean by "data gets sent" so that I can understand your requirement better?