Bonjour,
Je fais appelle encore une fois à la gentillesse des personnes de se forum pour me répondre.
Je dois créer une test Method pour ma classe Apex me servant a enregistrer dans un objet Mail__c les mails arrivant dans mon service de messagerie électronique.
Mon problème est que les Test Method je n'y comprend rien...
J'ai essayé avec les docs... rien à faire je ne vois pas ou est le problème de ma test method.
Quelqu'un pourrait-il m'éclairer au sujet des tests methods ou m'aider à corriger ma test method ?
Voici mon code pour mon service de messagerie :
et celui de ma test method :
Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 global class CreateMail implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env){ Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); String myPlainText= ''; // Add the email plain text into the local variable myPlainText = email.plainTextBody; // New Mail object to be created Mail__c[] newMail = new Mail__c[0]; // Add a new Mail newMail.add(new Mail__c(Description__c = myPlainText, Objet__c=email.subject, Adresse_Email__c = email.fromAddress)); // Insert the new Mail Object insert newMail; result.success = true; // Return the result for the Apex Email Service return result; } }
Je précise que derrière la réception et le stockage dans un objet de mon Mail, je déclenche un trigger pour faire une requête HTTP. Le trigger doit-il être intégré à la Test Method aussi ? Si il le faut je publierai mon code de Trigger.
Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 @isTest public class testMail { @isTest static void TestEmailCreate(){ // Create a new email and envelope object Messaging.InboundEmail email = new Messaging.InboundEmail() ; Messaging.InboundEnvelope env = new Messaging.InboundEnvelope(); email.plainTextBody='Test'; email.subject = 'TestMethod fait par Kevin '; email.fromAddress = 'rmencke@salesforce.com'; String myPlainText = email.plainTextBody; Mail__c[] MailTesting= new Mail__c[0]; MailTesting.add(new Mail__c(Description__c = myPlainText, Objet__c = email.subject, Adresse_Email__c = email.fromAddress)); insert MailTesting; CreateMail newMailtest= new CreateMail(); newMailtest.handleInboundEmail(email, env ); } }
Merci d'avance pour vos réponses,
Cordialement,
Kevin
Partager