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
David Bloomy BloomDavid Bloomy Bloom 

Help with test code

Hi, I have the below code working in my Sandbox. I need help writiing the test code to move my code to production. I am not an apex coder so I am looking for a kind person to write the test code for me.

You help would be grately appreciated

Thanks in advance

David

TRIGGER

trigger Conga_First_Email on Sabre_Hotels__c (after insert, after update) {
if(Trigger.new.size() == 1) { // NOTE: Conga does not allow batch requests. They will terminate your account.
     if(Trigger.new[0].First_Email_Sent__c && (Trigger.old == null || !Trigger.old[0].First_Email_Sent__c)) { // "Rising Edge" trigger
            CongaCallout.execute(UserInfo.getSessionId(), Trigger.new[0].Id);
     }
}
}

CLASS

public with sharing class CongaCallout {
    @future(callout=true)
    public static void execute(String sessionId, Id recordId) {
        Sabre_Hotels__c record = [SELECT Id, Name, Hotel_Email_Address__c FROM Sabre_Hotels__c WHERE Id = :recordId];
        PageReference ref = new PageReference('https://www.appextremes.com/apps/Conga/PM.aspx');
        ref.getParameters().putAll(
            new Map<String, String> {
             'sessionId' => sessionId,
             'serverUrl' => Url.getSalesforceBaseUrl().toExternalForm()+'/services/Soap/u/31.0/'+UserInfo.getOrganizationId(),
                'id' => recordId,
             'ReportId' => '00O9000000793dm?pv0='+record.Name,
             'EmailToID' => '003N000000DQGs4',
             'EmailAdditionalTo' => record.Hotel_Email_Address__c,
             'CETID' => 'a0JN0000002GElB',
             'TemplateId' => 'a0LN00000015SaB',
             'AC0' => '1',
             'SCO' => '1',
             'DS7' => '1',
             'APIMode' => '1',
             'APIMode' => '12'
            }
        );
        Http binding = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(ref.getUrl());
        req.setMethod('GET');
        req.setTimeout(120000);
      
        HttpResponse res = binding.send(req);
        if(res.getStatusCode()==200) {
            // Everything was okay
        } else {
            // An error occurred here
        }
        System.debug(LoggingLevel.ERROR, res);
}
}
James LoghryJames Loghry
I come across one of these posts every day.  And my response is the same.  We are not here to do your work for you.  With great power comes great responsibility.  If you're writing your own apex, you can write your own unit tests for that apex as well.  

See the following document, which has a nice step by step guide for building your first trigger as well as the test class for that trigger. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_HelloWorld.htm
David Bloomy BloomDavid Bloomy Bloom
Hi James, thanks for your response. Unfortunately for you there are a lot of really nice people out there and the code above was written by such an individual. As stated I am not an apex coder but many people here are. I completly understand not everyone wants to write other people code and thats why this is an open forum. I am only looking for help to improve my work environment.

thanks
David
James LoghryJames Loghry
Listen.  I'm here to help.  That's why I respond to these questions in the first place.  It's easy enough to skip over questions or ignore them altogether, but that's not what I'm doing here.  Also, I will not answer panhandling requests, or soliciting for free work, which you are doing when you ask someone to write the trigger for you.  I will do this for you for $250/hr, but not for free.  

You have written the above code, I assume, so you have a general idea of how to write an apex class.  What I'm suggesting is you take that knowledge, read the excellent tutorial on how to write a unit test for a trigger, apply some basic critical thinking, and attempt to tackle your unit test.

If or when you have issues getting your unit test working (with some evidence you have at least tried) then I will be more than happy to help you with those issues, as well other folks whom frequent these boards.

- James