• Ben Merton 15
  • NEWBIE
  • 124 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 28
    Replies
I am trying to migrate one developer org to another one.  I have created the project in eclipse and downloaded all the custom metadata from the first project.  Then I press Deploy to Server.  The first issue is that it seems to prevent me from copying page layouts for standard objects, which is a pain (any thoughts on how to deal with this?).  

User-added image

The second issue is that it generates a whole bunch of error messages when you press Validate Deployment:

User-added image

Is there any way to predict what kind of errors may come out from this type of procedure so you don't have to waste a whole bunch of time?

Are there any other tips about using Eclipse to complete this operation?
I don't seem to be able to call the following class from the Process Builder:

I know this could be written as a trigger, but I would prefer to do this from the Process Builder if that is possible as it is easier to manage all the Process flows from here.  Does this makes sense?

How can I modify this code to allow it to be called from the Process Builder?
 
public class POContactsController{
@InvocableMethod(Label='Insert PO Contacts')


    string poid;
    string vendorId;
    string contactid;
    
    public pageReference POContacts()
    {
       //Ensures that there is a Vendor on the PO or returns an error
       
        if (string.IsBlank(vendorid))
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Vendor selected on the Work Order'));
            return null;
        }
        
        //Deletes any items if they already exist
        
          List<unifize__PO_Contact__c> existingpocontacts = [select ID from unifize__PO_Contact__c where unifize__Purchase_Order__c = :poid];
        if(existingpocontacts.size() != 0)
        {
        delete existingpocontacts;
        }
        
        //Checks that there are Contacts assigned to POs on the related Contacts and returns error if not
        
        List<Contact> Contactlist = [select ID, Email, MobilePhone, Phone, Name FROM Contact where unifize__Purchase_Orders__c=TRUE AND Accountid = :VendorId];
        if (Contactlist.size() == 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Contacts assigned to receive POs for this Vendor'));
        System.debug('Contact List Size' + Contactlist.size());
        return null;
        }
         
        List<unifize__PO_Contact__c> POContactList = new List<unifize__PO_Contact__c>();
        
        for (Contact POContactItem : ContactList)
        {
        
        unifize__PO_Contact__c newpocontact = new unifize__PO_Contact__c();
        newpocontact.unifize__Contact__c=contactid;
     
            POContactList.add(newpocontact);
            
        }
        if (POContactList.size() > 0)
        {
            insert POContactList;
        }
        return new PageReference('/' + poId);
    }
}

 
This trigger is returning an error saying:  Apex trigger unifize.POContacts caused an unexpected exception, contact your administrator: unifize.POContacts: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Class.unifize.POContactsController.: line 9, column 1
 
trigger POContacts on unifize__Purchase_Order__c (before insert, before update) {

POContactsController newpocs= new POContactsController();

}

This is the class:
 
public class POContactsController{
    string poid;
    string vendorId;
    string contactid;
    

    public POContactsController()
    {
        poId = ApexPages.currentPage().getParameters().get('id');
        vendorId = ApexPages.currentPage().getParameters().get('VendorId');
        
        List<Contact> contactidlist = [select Id FROM Contact WHERE unifize__Purchase_Orders__c=TRUE AND Accountid = :VendorId];
        contactid=contactidlist[0].id;
     
        System.debug('PO ID 1' + poId);
        System.debug('Vendor ID 1' + vendorId);

    }
    public pageReference POContacts()
    {
       //Ensures that there is a Vendor on the PO or returns an error
       
        if (string.IsBlank(vendorid))
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Vendor selected on the Work Order'));
            return null;
        }
        
        //Deletes any items if they already exist
        
          List<unifize__PO_Contact__c> existingpocontacts = [select ID from unifize__PO_Contact__c where unifize__Purchase_Order__c = :poid];
        if(existingpocontacts.size() != 0)
        {
        delete existingpocontacts;
        }
        
        //Checks that there are Contacts assigned to POs on the related Contacts and returns error if not
        
        List<Contact> Contactlist = [select ID, Email, MobilePhone, Phone, Name FROM Contact where unifize__Purchase_Orders__c=TRUE AND Accountid = :VendorId];
        if (Contactlist.size() == 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Contacts assigned to receive POs for this Vendor'));
        System.debug('Contact List Size' + Contactlist.size());
        return null;
        }
         
        List<unifize__PO_Contact__c> POContactList = new List<unifize__PO_Contact__c>();
        
        for (Contact POContactItem : ContactList)
        {
        
        unifize__PO_Contact__c newpocontact = new unifize__PO_Contact__c();
        newpocontact.unifize__Contact__c=contactid;
     
            POContactList.add(newpocontact);
            
        }
        if (POContactList.size() > 0)
        {
            insert POContactList;
        }
        return new PageReference('/' + poId);
    }
}

Please help!!
I am trying to create a test class for the following:
public class CreateIndentController{
    string workOrderId;
    string productId;
    string woquantitylist;
    decimal woquantity;
    decimal sequenceno;
    datetime wocompletiondate;
    datetime requireddate;

    public CreateIndentController()
    {
        workOrderId = ApexPages.currentPage().getParameters().get('id');
        productId = ApexPages.currentPage().getParameters().get('productId');
        
        List<unifize__Work_Order__c> woquantitylist = [select unifize__Completion_Date_Time__c, unifize__Quantity__c FROM unifize__Work_Order__c WHERE unifize__Product__c = :productId];
        woquantity=woquantitylist[0].unifize__Quantity__c;
        wocompletiondate = woquantitylist[0].unifize__Completion_Date_Time__c;
        
        List<unifize__BOM_Item__c> cycletimesequencelist = [select unifize__Cycle_Time__c, unifize__Sequence_No__c FROM unifize__BOM_Item__c WHERE unifize__Product__c = :productId];
        sequenceno=cycletimesequencelist[0].unifize__Sequence_No__c;
          
        
        System.debug('Product ID 1' + productId);
        System.debug('Work Order ID 1' + workorderId);
        System.debug('Work Order Quantity' + woquantity);
    }
This is how far I have got so far.  I realise I am completely way off, but it is hours and I am completely frustrated.  The main problem is that the variable is 'invisible', presumably because it is being assigned to a list.  Also, I don't really understand the method of actually testing whether the if clause passes or fails.  Please help!
 
public class TestCreateIndentController{
    
static testMethod void testIndentController()

{

CreateIndentController abc = new CreateIndentController();
List<unifize__Work_Order__c> woquantitylist = new List<unifize__Work_Order__c>{'system.now()','1'};
abc.woquantity = 1.0;
abc.sequenceno = 1.0;
abc.wocompletiondate = system.now();
abc.requireddate= system.now();
 
ApexPages.currentPage().getParameters().put('abc.id', 'a0M1500000UGHdo');
Apexpages.currentpage().getparameters().put('abc.productId' , 'a041500000amOvl');
 

    
    //if (string.IsBlank(abc.productId))
    //    {
    //        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No product selected on the Work Order'));
            //return null;
    //    }
    // System.debug('Product ID 1' + abc.productId);   
 }         
 }


 
I am trying to incorporate a button that does the following:

1.  Press Button
2.  Check if there are existing records
3.  If there aren't existing records, run the controller to execute the clone
4.  If there are existing records, give a choice "Yes" or "No"
5.  If Yes, run the controller to execute the clone]
6.  If no, close the box and don't do anything

I need to incorporate it on this code:
 
//////Class before

List<Material_Request__c> womaterialrequest = [select Indent_Quantity__c, Good_Service__c from Material_Request__c where Work_Order__c = :workorderid];
        if(womaterialrequest.size() != 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Indents already on the Work Order.  Please delete before Adding Indent Again'));
        return null;
        }

///////Class after

Any help
I can see how you can create the metadata and the settings, but I don't understand how you can then assign a value to these?  Am I missing something?
I am trying to incorporate Inline Editing in a related list.  Salesforce seems to have a Mass Edit & Mass delete button app, but I am look for something customised.

Any ideas on how to get started with this?
Supposing I have a Work Order with Completion_Date_Time__c and I am trying to work out the Date_Time of material required based both on a Delivery_Time__c AND the Business Hours / Holidays.

So working backwards it would be just Completion_Date_Time__c MINUS the Delivery_Time__c MINUS the NON-Business Hours/Holidays.  But what if that calculation AGAIN lands on a holiday / crosses a holiday.  You would need to parse this out?  Or am I completely missing something?

Are there any methods that can perform this calculation?



 
I am trying to add days to an existing date variable as per the following:
 
public class CreateIndentController{

    decimal cycletime;
    decimal sequenceno;
    date completiondate;
    date requireddate;

    public CreateIndentController()
    {
        productId = ApexPages.currentPage().getParameters().get('unifize_Completion_Date__c');
       
        List<unifize__BOM_Item__c> cycletimesequencelist = [select unifize__Cycle_Time__c, unifize__Sequence_No__c FROM unifize__BOM_Item__c WHERE unifize__Product__c = :productId];
        cycletime=cycletimesequencelist[0].unifize__Cycle_Time__c;
        sequenceno=cycletimesequencelist[0].unifize__Sequence_No__c;
    
    }
    public pageReference onLoad()
    {
       
   
        List<unifize__BOM_Item__c> bomItems = [select unifize__Quantity__c, unifize__GSI_No__c, unifize__Quantity_UOM__c from unifize__BOM_Item__c where unifize__Product__c = :productId];

         
                List<unifize__Material_Request__c> indents = new List<unifize__Material_Request__c>();
        for (unifize__BOM_Item__c item : bomItems)
        {
            indent.unifize__Required_Date__c=completiondate.addDays(-1*cycletime/24);
            indents.add(indent);
        }
        if (indents.size() > 0)
        {
            insert indents;
        }
        return new PageReference('/' + workOrderId);
    }
}
I am having a problem with the following line:

 indent.Required_Date__c=completiondate.addDays(-1*cycletime/24);

It is returning this error 
Error: Compile Error: Method does not exist or incorrect signature: [Date].addDays(Decimal) at line 60 column 46

Can you help?
 
I have spent a long time looking around for this.  Some answers seem to say you have to log a case with the Success Community, but when you try to do this it gives an error for the "I need assistance with Development".

Some people say that you can deprecate a penultimate package and then delete components.

However, I can find a single consisten approach to completing this.  Has anyone got a clear idea??
I am trying to do a multiplication between a string and a method called using the dot notation:

indent.Indent_Quantity__c = item.Quantity__c*woquantity;

It is saying that "Arithmetic expressions must use numeric arguments

Can you help?

Full code below...
 
public class CreateIndentController{
    string workOrderId;
    string productId;
    string woquantity;

    public CreateIndentController()
    {
        workOrderId = ApexPages.currentPage().getParameters().get('id');
        productId = ApexPages.currentPage().getParameters().get('productId');
        woquantity = ApexPages.currentPage().getParameters().get('quantity');
        System.debug('Product ID 1' + productId);
        System.debug('Work Order ID 1' + workorderId);
    }
    public pageReference onLoad()
    {
               
                List<Material_Request__c> indents = new List<Material_Request__c>();
        for (BOM_Item__c item : bomItems)
        {
            Material_Request__c indent = new Material_Request__c();
            indent.Work_Order__c = workOrderId;
            indent.Indent_Quantity__c = item.Quantity__c*woquantity;
            indent.Good_Service__c = item.GSI_No__c;
            indents.add(indent);
        }
        if (indents.size() > 0)
        {
            insert indents;
        }
        return new PageReference('/' + workOrderId);
    }
}

 
I have a class wherein an error is currently thrown if the records contained in a related list already exist when a clone button is pressed:
 
//////Class before

List<Material_Request__c> womaterialrequest = [select Indent_Quantity__c, Good_Service__c from Material_Request__c where Work_Order__c = :workorderid];
        if(womaterialrequest.size() != 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Indents already on the Work Order.  Please delete before Adding Indent Again'));
        return null;
        }

///////Class after
I am looking to convert this to a popup warning that states "Overwrite Existing Material Requests?", with a Yes/No choice.

If the user selects yes, then all the existing records in the list should be deleted, before the rest of the class is performed.  If they select No, then it should return to the existing record without any changes.

Any ideas?
 
Suppose I want to use a free app, like SuperClone, with in my own managed package.  Can I add this to my own managed package and deploy this to third parties?
I have a custom button that generates a PDF HTML page for Invoicing using a controller with queries.

At the moment, the user has to wait for approval and then press the PDF button , then save this to the 'Downloads' on the hard drive, then 'Send and Email', then click 'Template', then attach the saved PDF, then find the BCC people etc etc.  This is a pain.

It would be much better if this was automatically sent on approval to all the Contacts defined to receive Invoices.

What methodology should I use for attaching a PDF to an email and sending it?
Is there any methodology that I should be using to send an email using an Apex class at a specific time of day?
I am trying to write an Apex class that clones a record from a related record.  My app structure is a little complex:

Work_Order__c (Parent of Material Indent)
Custom Fields:  Quantity__c, Delivery Date__c
Custom Lookup:  Product__c

Material_Indent__c (Child of Work Order Object)
Custom Fields:  Quantity__c
Custom Lookup:  GSI_No__c, Work_Order__c

Product__C Object (Parent of BOM Line Item Object)
Custom Fields:  Irrelevant

BOM_Items (Child of Parent Product Object)
Custom Fields: Quantity__c
Custom Lookup: GSI_No__c

I am tryig to write a trigger that automates the process of creating an Indent from the BOM Items (which are related to the Product, which is in turn in the lookup in the Work Order).

The trigger will be initiated from the Work Order page with a button ("Create Indent").

This is where I am so far.  I am confused about whether I am even heading in the right direction?  I have doubts about the following:

1.  Is a trigger even a way to go for this?
2.  Will Page Reference return the Products__c custom field ID if I am running this via a button on the Work Order (Products__c is a Custom Field on Work_Order__c
3.  Is the method for creating a set of the BOM Items which have a Products__c=the Products__c found from the Page Reference on the Work Order correct?
4.  Am I correctly traversing the objects using BOMItemSet.add(BOMItems.GSI_No__c.id) to add the ID of the GSI number to the list?
 
trigger Indent on Work_Order__c (before update) {

 //   Create variable for capturing Product ID

Page Reference productid=Product__c.id; 

  // Create a set of all records

  Set<String> BOMItemSet = new Set<String>();
  for (BOM_Items__c BOMItems : Trigger.new) {

// Add the fields for Quantity and GSI No.

    if (BOMItems.Product__c = productid) {
      BOMItemSet.add(BOMItems.Quantity__c);
      BOMItemSet.add(BOMItems.GSI_No__c.id);  //NB This is a lookup
  }

After this, I was going to create another trigger to insert the set that I have created above into Material_Indents, the child record of the Product object.  However, I don't want to go on with this unless I am clear with the first step!

Please help!




 
Merry Christmas!

I am trying to write my first trigger, and am really stuck with the method.  I have three custom objects:  Product__c, BOM__c, and BOM_Items__c

Product is the grandparent, BOM is the parent and BOM Items is the child.

I also have a lookup from BOM Items to Product, so effectively the Product is also the parent of BOM items.  It is a strange, incestous relationship.

When I create a BOM Item, I want to trigger the ID of the Product in the BOM field, so that both BOM Items and BOM mention the Product. (ie trigger from the Product__c lookup field in the BOM__c object TO the Product__c lookup field in the BOM_Item__c field.  This doesn't have to happen for ALL records ALL the time, only for the records as and when they are created.

As a novice, my initial thought on the methodology would be something like this:
trigger ProductName on BOM_Item__c (before insert, before update) {
BOM.Product__c ProductIDBOM;
Product__c ProductIDBOMItem;

for (BOM_Item__c trigger : trigger.new)
{
ProductIDBOM=BOM__c.Product__c;
ProductIDBOMItem=ProductIDBOM;
}
}


However, when I read about triggers on these pages, everyone seems to start with having to build a map of the IDs and then selecting from the map to find the ID etc etc.  I can't work out whether this is because they want to update more than one record at a time, or just because this is best practice.  Please help!!

Ben





From what I can see on the boards, the methodology should be:

1.  Build a map
I am trying to create a Test Class for this:
 
//This class is used as a controller for allowing the Divisions tab to land directly on the List View

public class DivisionsTabOverride{
public PageReference exit(){
//change the Any_ObjectName__c with your Custom or Standard Object name.
Schema.DescribeSObjectResult anySObjectSchema = Division__c.SObjectType.getDescribe();
String objectIdPrefix = anySObjectSchema.getKeyPrefix();
PageReference pageReference = new PageReference('/'+objectIdPrefix);
pageReference.setRedirect(true);
return pageReference;
}
}

This is what I have so far.  It passes the test when I press run, but I am unable to see any corresponding code coverage change in the class above.  Also, please let me know if I need to add anything to this test to get coverage?
 
@isTest
//This class is used as a controller for allowing the Divisions tab to land directly on the List View

public class TestDivisionsTabOverride{
static testmethod PageReference exit(){
//change the Any_ObjectName__c with your Custom or Standard Object name.
Schema.DescribeSObjectResult anySObjectSchema = Division__c.SObjectType.getDescribe();
String objectIdPrefix = anySObjectSchema.getKeyPrefix();
System.assert(objectIdPrefix.length()==3);

PageReference pageReference = new PageReference('/'+objectIdPrefix);
pageReference.setRedirect(true);
return pageReference;

}
}

 
I am trying to bypass the standard functionality of a custom tab so that when a user clicks on the tab, it takes them straight to the list view of that item.  I have a controller:
public class PageRef{
public PageReference exit(){
//change the Any_ObjectName__c with your Custom or Standard Object name.
Schema.DescribeSObjectResult anySObjectSchema = Corporate_Statements__c.SObjectType.getDescribe();
String objectIdPrefix = anySObjectSchema.getKeyPrefix();
PageReference pageReference = new PageReference('/'+objectIdPrefix+'/o');
pageReference.setRedirect(true);
return pageReference;
}
}
and a VisualForce page
<apex:page controller="PageRef" action="{!exit}"> </apex:page>
I have overridden the tab with the visualforce page.  However, when you click on the tab now, it seems to go into an endless loop, flicking between two servers c.na22.visual.force.com and na22.visual.force.com.  I have tried loading in another browser (IE) and you can hear the page 'click' opening repeatedly ever few seconds as it evidently tries to open the page.  I have tried creating a VisualForce tab and applying the same functionality, and the same problem occurs

Someone else has checked out the code and said it works okay for them.  This is such a pain!  Any help??

Ben

 
I am using this code to return the first three letters of a Custom Object's id, so that I can then bypass the standard object landing page and go straight to a list view of that Custom Object:
 
//This class is used as a controller for allowing the Corporate Statements tab to land directly on the List View

public class PageRef{
public PageReference exit(){
//change the Any_ObjectName__c with your Custom or Standard Object name.
Schema.DescribeSObjectResult anySObjectSchema = Corporate_Statements__c.SObjectType.getDescribe();
String objectIdPrefix = anySObjectSchema.getKeyPrefix();
PageReference pageReference = new PageReference('/'+objectIdPrefix+'/o');
pageReference.setRedirect(true);
return pageReference;
}
}

I am not clear exactly how I am meant to now call this into a VisualForce page:
 
<apex:page controller="PageRef">
action = "{!URLFOR(pageReference)};
</apex:page>
Any help?
 
This trigger is returning an error saying:  Apex trigger unifize.POContacts caused an unexpected exception, contact your administrator: unifize.POContacts: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Class.unifize.POContactsController.: line 9, column 1
 
trigger POContacts on unifize__Purchase_Order__c (before insert, before update) {

POContactsController newpocs= new POContactsController();

}

This is the class:
 
public class POContactsController{
    string poid;
    string vendorId;
    string contactid;
    

    public POContactsController()
    {
        poId = ApexPages.currentPage().getParameters().get('id');
        vendorId = ApexPages.currentPage().getParameters().get('VendorId');
        
        List<Contact> contactidlist = [select Id FROM Contact WHERE unifize__Purchase_Orders__c=TRUE AND Accountid = :VendorId];
        contactid=contactidlist[0].id;
     
        System.debug('PO ID 1' + poId);
        System.debug('Vendor ID 1' + vendorId);

    }
    public pageReference POContacts()
    {
       //Ensures that there is a Vendor on the PO or returns an error
       
        if (string.IsBlank(vendorid))
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Vendor selected on the Work Order'));
            return null;
        }
        
        //Deletes any items if they already exist
        
          List<unifize__PO_Contact__c> existingpocontacts = [select ID from unifize__PO_Contact__c where unifize__Purchase_Order__c = :poid];
        if(existingpocontacts.size() != 0)
        {
        delete existingpocontacts;
        }
        
        //Checks that there are Contacts assigned to POs on the related Contacts and returns error if not
        
        List<Contact> Contactlist = [select ID, Email, MobilePhone, Phone, Name FROM Contact where unifize__Purchase_Orders__c=TRUE AND Accountid = :VendorId];
        if (Contactlist.size() == 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'No Contacts assigned to receive POs for this Vendor'));
        System.debug('Contact List Size' + Contactlist.size());
        return null;
        }
         
        List<unifize__PO_Contact__c> POContactList = new List<unifize__PO_Contact__c>();
        
        for (Contact POContactItem : ContactList)
        {
        
        unifize__PO_Contact__c newpocontact = new unifize__PO_Contact__c();
        newpocontact.unifize__Contact__c=contactid;
     
            POContactList.add(newpocontact);
            
        }
        if (POContactList.size() > 0)
        {
            insert POContactList;
        }
        return new PageReference('/' + poId);
    }
}

Please help!!
I am trying to incorporate a button that does the following:

1.  Press Button
2.  Check if there are existing records
3.  If there aren't existing records, run the controller to execute the clone
4.  If there are existing records, give a choice "Yes" or "No"
5.  If Yes, run the controller to execute the clone]
6.  If no, close the box and don't do anything

I need to incorporate it on this code:
 
//////Class before

List<Material_Request__c> womaterialrequest = [select Indent_Quantity__c, Good_Service__c from Material_Request__c where Work_Order__c = :workorderid];
        if(womaterialrequest.size() != 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Indents already on the Work Order.  Please delete before Adding Indent Again'));
        return null;
        }

///////Class after

Any help
Supposing I have a Work Order with Completion_Date_Time__c and I am trying to work out the Date_Time of material required based both on a Delivery_Time__c AND the Business Hours / Holidays.

So working backwards it would be just Completion_Date_Time__c MINUS the Delivery_Time__c MINUS the NON-Business Hours/Holidays.  But what if that calculation AGAIN lands on a holiday / crosses a holiday.  You would need to parse this out?  Or am I completely missing something?

Are there any methods that can perform this calculation?



 
I have spent a long time looking around for this.  Some answers seem to say you have to log a case with the Success Community, but when you try to do this it gives an error for the "I need assistance with Development".

Some people say that you can deprecate a penultimate package and then delete components.

However, I can find a single consisten approach to completing this.  Has anyone got a clear idea??
I have a class wherein an error is currently thrown if the records contained in a related list already exist when a clone button is pressed:
 
//////Class before

List<Material_Request__c> womaterialrequest = [select Indent_Quantity__c, Good_Service__c from Material_Request__c where Work_Order__c = :workorderid];
        if(womaterialrequest.size() != 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Indents already on the Work Order.  Please delete before Adding Indent Again'));
        return null;
        }

///////Class after
I am looking to convert this to a popup warning that states "Overwrite Existing Material Requests?", with a Yes/No choice.

If the user selects yes, then all the existing records in the list should be deleted, before the rest of the class is performed.  If they select No, then it should return to the existing record without any changes.

Any ideas?
 
I am trying to write an Apex class that clones a record from a related record.  My app structure is a little complex:

Work_Order__c (Parent of Material Indent)
Custom Fields:  Quantity__c, Delivery Date__c
Custom Lookup:  Product__c

Material_Indent__c (Child of Work Order Object)
Custom Fields:  Quantity__c
Custom Lookup:  GSI_No__c, Work_Order__c

Product__C Object (Parent of BOM Line Item Object)
Custom Fields:  Irrelevant

BOM_Items (Child of Parent Product Object)
Custom Fields: Quantity__c
Custom Lookup: GSI_No__c

I am tryig to write a trigger that automates the process of creating an Indent from the BOM Items (which are related to the Product, which is in turn in the lookup in the Work Order).

The trigger will be initiated from the Work Order page with a button ("Create Indent").

This is where I am so far.  I am confused about whether I am even heading in the right direction?  I have doubts about the following:

1.  Is a trigger even a way to go for this?
2.  Will Page Reference return the Products__c custom field ID if I am running this via a button on the Work Order (Products__c is a Custom Field on Work_Order__c
3.  Is the method for creating a set of the BOM Items which have a Products__c=the Products__c found from the Page Reference on the Work Order correct?
4.  Am I correctly traversing the objects using BOMItemSet.add(BOMItems.GSI_No__c.id) to add the ID of the GSI number to the list?
 
trigger Indent on Work_Order__c (before update) {

 //   Create variable for capturing Product ID

Page Reference productid=Product__c.id; 

  // Create a set of all records

  Set<String> BOMItemSet = new Set<String>();
  for (BOM_Items__c BOMItems : Trigger.new) {

// Add the fields for Quantity and GSI No.

    if (BOMItems.Product__c = productid) {
      BOMItemSet.add(BOMItems.Quantity__c);
      BOMItemSet.add(BOMItems.GSI_No__c.id);  //NB This is a lookup
  }

After this, I was going to create another trigger to insert the set that I have created above into Material_Indents, the child record of the Product object.  However, I don't want to go on with this unless I am clear with the first step!

Please help!