+ Start a Discussion
Management 20Management 20 

Test Class for Apex Triggers

Hi All
I'm completely new to Apex triggers but have managed to put together the trigger below to automatically send account records to a 2nd salesforce org when the record is created usng S2S .The trigger works perfectly on our sandbox but I am now unable to deploy it to production because the relevant tests have not been run. I've tried looking at documentation on how to do this but I've had no success so far. If anyone could help me out on this I'd be extremely grateful!

trigger SendAccountsToConnection on Account (after insert) {
        PartnerNetworkConnection conn = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection  where ConnectionStatus = 'Accepted' and ConnectionName = 'xxxabc'];
        List<PartnerNetworkRecordConnection> recordConnectionToInsert  = new List<PartnerNetworkRecordConnection>  ();
        for (Account acc : Trigger.new){
            PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();

            newrecord.ConnectionId = conn.Id;
            newrecord.LocalRecordId = acc.id;  
            newrecord.SendClosedTasks = false;
            newrecord.SendOpenTasks = false;
            newrecord.SendEmails = false;
        if (recordConnectionToInsert.size() > 0){
            System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
            insert recordConnectionToInsert;
you can better use a handler class or helper class along with the trigger.
Management 20Management 20
I am really looking for some assistance with the code as I have little to no experience with this.