2016-09-20 2 views
0

이 프로젝트의 최종 목표는 회사 등록 보증서 페이지에 제품을 등록한 각 고객의 연락처와 사례를 만드는 것입니다.Salesforce APEX 자동 생성 문의처

나는 이미 MySQL 데이터베이스에 연결하고 필요한 정보를 .xlsx 파일에 저장 한 다음 .xlsx 파일에서 동일한 데이터를 현재 salesforce로 보내고있는 다른 python 스크립트를 저장하고 케이스 용으로 작동하는 python 스크립트가 있습니다. 또는 연락처가 아니라 둘 다. Apex 트리거는 실제로 웹에서 케이스로 또는 이메일에서 케이스로만 작동하지만 어떤 이유로 파이썬에서는 작동하지 않습니다.

약 6 시간마다 무기한으로 트리거되는 내용입니다. 이미 데이터베이스에서 동일한 데이터를 두 번 가져 오지 않는 위치로 설정 했으므로 각 테이블의 새 열에 '1'을 쓰고 MySQL 데이터베이스의 새 연락처 만 가져 와서 '1'이 있는지 확인합니다 그리고 만약 그렇다면 그것을 건너 뜁니다. 연락처와 사례를 만드는 경우를 제외하고는 모두 작동합니다. 고객이 제품 문제 해결을 위해 전화를 할 때 필요한 모든 주소 정보를 보유 할 것이기 때문에 구체적으로 연락해야합니다. 제품 및 일련 번호가 삭제되어 고객에게 보낼 수있는 곳이기 때문에 케이스도 생성해야합니다. 사례가 생성되면 이메일.

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!'); 
} 
} 
+0

질문에 혼란 스럽습니다. 테스트 메소드가 데이터베이스에 이미 존재하는 데이터로 작업하려고하거나 테스트 메소드로 트리거되지 않을 때 트리거가 작동하지 않는 이유를 묻고 있습니까? 트리거 코드 또는 추가 컨텍스트를 제공해 주시겠습니까? 테스트 메소드가 기존 연락처/사례에 액세스 할 수있게하려면 "@isTest (SeeAllData = true)"플래그 [https://developer.salesforce.com/docs/atlas.en-us]를 추가해야합니다. apexcode.meta/apexcode/apex_testing_seealldata_using.htm] –

+0

위의 테스트 클래스는 트리거와 함께 작동하지만 [email protected], John Doe 및 subject가 사례 - 피드백이있는 경우에만 작동합니다. 나는 모든 경우에 대해 방아쇠가 작동하는 곳으로 만들려고 노력하고 있습니다. 여기에는 SuppliedEmail이 채워져 있고, John Doe의 미리 정의 된 변수가있는 테스트가 아닙니다. 나는 트리거와 클래스를 가지고 있습니다 : https://developer.salesforce.com/page/Autocreating_Contacts_From_Web_To_Case –

+0

Ok. 케이스에 전자 메일 주소 [email protected]과 John Doe라는 이름이있을 때 테스트 클래스 만 작동하거나 트리거 만 작동한다고 말하는 것입니까? 트리거 코드는 입력을 완전히 인식하지 못합니다. 이메일 주소가 다른 케이스에 대한 테스트 방법은 무엇입니까? –

답변

0

나는 그것을 얻었다.

그래서 Simple-Salesforce로 이미 작업했던 것처럼 연락처를 만든 다음 Python에서 Selenium 패키지를 사용하여 로컬로 호스팅 된 웹 - 케이스 HTML 파일을 열고 .xlsx 시트의 데이터를 보내 제출하십시오. .xlsx 시트의 각 고객에 대한 사례를 만들고 확인 된 salesforce는 연락처와 사례를 서로 연관시킵니다.

관련 문제