Reputation:
So my end goal for this project is to create a contact and a case for each customer that registers a product on my companies warranty registration page.
I have already got a python script that connects to a MySQL database and saves the needed info into an .xlsx file and then another python script currently sending that same data from the .xlsx file into salesforce and it works for a Case OR a Contact but not both. Apex trigger only works if I actually do a web-to-case or email-to-case but for some reason does not work with python.
This will be something that will be triggered roughly every 6 hours indefinitely. I already got it setup to where it does not pull the same data twice from the database so it only grabs new contacts from the MySQL database by writing a '1' to a new column in each table and does a check if '1' exists and if it does then skip it. Everything is working EXCEPT for creating a Contact AND a Case. Contact specifically because it will have all the address information we need for when a customer calls in for troubleshooting of their product, we want a case also created because that is where the product and serial numbers are taken down and allows a trigger to send the customer an email once the case has been created.
public class CaseAutocreateContactTest {
public static testMethod void testBulkContactsGetCreated() {
List<Case> newCases = new List<Case>();
for (Integer i = 0; i<100; i++) {
Case c = new Case(SuppliedEmail='[email protected]' + i,
SuppliedName='John Doe' + i,
Subject='Feedback - Something' + i);
newCases.add(c);
}
insert newCases;
System.debug('here');
List<Id> newCaseIds = new List<Id>();
for (Case caseObj:newCases) {
newCaseIds.add(caseObj.Id);
}
List<Case> updatedCases = [Select ContactId From Case Where Id in :newCaseIds];
for (Case caseObj:updatedCases) {
System.debug(caseObj.Id + ' ' + caseObj.ContactId);
System.assert(caseObj.ContactId!=null,'There should be no null contacts');
}
}
public static testMethod void testContactGetsCreated() {
Case c = new Case(SuppliedEmail='[email protected]',
SuppliedName='John Doe',
Subject='Feedback - Something');
insert c;
List<Contact> johnDoes = [select Id from Contact where Email='[email protected]'];
//there should be only 1 -- the trigger should not have created another
System.assert(johnDoes.size()==1, 'There should be one John Doe!');
Case caseObj = [select ContactId from Case where Id=:c.Id];
System.assert(caseObj.ContactId!=null,'There should be no null contact on the case');
}
public static testMethod void testNoDupesAreCreated() {
Contact cnt1 = new Contact(FirstName = 'John',
LastName = 'Doe',
Email='[email protected]');
insert cnt1;
Case case1 = new Case(SuppliedEmail='[email protected]',
SuppliedName='John Doe',
Subject='Feedback - Something');
insert case1;
List<Contact> johnDoes = [select Id from Contact where Email='[email protected]'];
//there should be only 1 -- the trigger should not have created another
System.assert(johnDoes.size()==1, 'There should be only one John Doe!');
}
public static testMethod void testEmailNameDoesntGetCreated() {
Case c = new Case(SuppliedEmail='[email protected]',
SuppliedName='[email protected]',
Subject='Feedback - Something');
insert c;
List<Contact> johnDoes = [select Id from Contact where Email='[email protected]'];
//there should be only 1 -- the trigger should not have created another
System.assert(johnDoes.size()==0, 'There should be no John Does!');
}
}
Upvotes: 1
Views: 2269
Reputation:
I got it to work.
So I first created a Contact like I already had working with Simple-Salesforce and then used Selenium package in Python to open web-to-case html file hosted locally and send the data from the .xlsx sheet and submit. Confirmed it creates a case for each customer in .xlsx sheet and confirmed salesforce associates the contact and case with one another.
Upvotes: 1