You need to sign in to do that
Don't have an account?
David 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);
}
}
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);
}
}
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
thanks
David
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