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
Miguel Gonzalez 4Miguel Gonzalez 4 

trigger (after insert) - load List data to custom SObject

I'm working on a trigger project in the Sandbox.  It's supposed to set off anytime someone updates the field "FTP_to_Case__c" on "FTP Actions".  I have the initial stage, to set activate the trigger, set up, but I'm new to SFDC and how to take that "Action_Date_Time__c" data collected and transfer it to my new custom object "Last_Upload" (which is on the object "Case") is where I'm a bit lost. 

Here is where I stand so far.
My coding for an Apex Trigger...so far.  I've declared the List, what I want to initiate the Trigger, and the Update command.
Any guidance will be much appreciated!

Miguel G.

Best Answer chosen by Miguel Gonzalez 4
pconpcon
This code should get you started
 
trigger UpdateFTPCases on FTP_Action__c  (after insert) {
    List<Case> casesToUpdate = new List<Case>();

    for (FTP_Action__c f: trigger.new) {
        if (f.FTP_to_Case__c != null) {
            casesToUpdate.add(new Case(
                Id = f.FTP_to_Case__c,
                Last_Upload__c = f.Action_Date_Time__c
            ));
        }
    }

    if (!casesToUpdate.isEmpty()) {
        update casesToUpdate;
    }
}

What it does is iterate over all of your FTP_Action__c objects and then creates a "new" Case record with the Last_Upload__c set to the Action_Date_Time__c.  Since we set the Id of the case to the FTP_to_Case__c field when we call the update casesToUpdate we will update the record with that Id.

All Answers

pconpcon
This code should get you started
 
trigger UpdateFTPCases on FTP_Action__c  (after insert) {
    List<Case> casesToUpdate = new List<Case>();

    for (FTP_Action__c f: trigger.new) {
        if (f.FTP_to_Case__c != null) {
            casesToUpdate.add(new Case(
                Id = f.FTP_to_Case__c,
                Last_Upload__c = f.Action_Date_Time__c
            ));
        }
    }

    if (!casesToUpdate.isEmpty()) {
        update casesToUpdate;
    }
}

What it does is iterate over all of your FTP_Action__c objects and then creates a "new" Case record with the Last_Upload__c set to the Action_Date_Time__c.  Since we set the Id of the case to the FTP_to_Case__c field when we call the update casesToUpdate we will update the record with that Id.
This was selected as the best answer
Miguel Gonzalez 4Miguel Gonzalez 4
Thanks!  It worked great.  Appreciate the guidance and help.
pconpcon
Great! Glad to hear. If you could please mark the answer as "Best Answer" so that it can help others in the future as well as removing it from the unsolved queue, I'd greatly appreciate it.
Miguel Gonzalez 4Miguel Gonzalez 4
One last question, I need to 'bulk test' my trigger.  I'm finding some suggestions on the Salesforce section of Stack Exchange, but not having much luck converting them to use with my trigger.  This is the link to the one I'm trying to adjust and use right now, with no luck.
http://salesforce.stackexchange.com/questions/15237/bulk-testing-trigger
If you know anything about bulk testing, I'd appreciate that as well.  Just trying to add all these suggestions to my toolbox.
pconpcon
I actually know quite a bit about bulk testing.  I would recommend you read over my presentation on testing [1] and then take a look at my Bulk Testing Hands-On Training I wrote [2].

[1] http://pcon.github.io/presentations/testing/#bulk-intro
[2] https://github.com/pcon/bulkhandson