Forum Replies Created

  • TEST CLASS:

    @istest
    public class TestEtoCKroger {
    static testMethod void TestEtoCKroger () {

    // create a new email and envelope object
    Messaging.InboundEmail email = new Messaging.InboundEmail() ;
    Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

    Map<ID,Schema.RecordTypeInfo> rt_Map = Case.sObjectType.getDescribe().getRecordTypeInfosById();
    Id RecordTypeIdCase = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Service - Managed Service Case').getRecordTypeId();
    Id rtId = RecordTypeIdCase;

    Account acc = new Account();
    acc.Name = 'Test Account';
    acc.BillingStreet = '123 St.';
    acc.BillingCity = 'Springfield';
    acc.BillingState = 'IL';
    acc.BillingPostalCode = '62704';
    insert acc;

    SVMXC__Site__c loc = new SVMXC__Site__c();
    loc.Name = 'Sample Test';
    loc.NTT_Metro_Remote__c = 'Zone A';
    loc.SVMXC__Street__c = '123 E Main St.';
    loc.SVMXC__City__c = 'Springfield';
    loc.SVMXC__State__c = 'ILLINOIS';
    loc.SVMXC__Zip__c = '62511';
    loc.SVMXC__Country__c = 'United States';
    loc.NTT_Legacy_Location_ID__c = 'Sample Test';
    loc.SVMXC__Account__c = acc.Id;
    loc.BSP_Location_Contact_Phone__c = '111 222 1343';
    insert loc;
    Case cse = new CASE(
    Subject = 'Test Subject',
    Description = 'Test description',
    Origin = 'Email',
    SVMXC__Site__c = loc.Id,
    Status = 'New',
    recordtypeid = rtId,
    accountid= acc.Id,
    KA_PO__c = '1001',
    BSP_Location_Contact_Phone__c = '111 222 3443',
    Case_Type__c = 'Service Request',
    Location_Contact_Name__c = 'Test Man'

    );
    insert cse;
    // setup the data for the email
    email.subject = 'Kroger Service Call Notification 10935174/1 (HIGH) Sample Test';
    env.fromAddress = '[email protected]';
    email.plainTextBody = 'email body for testing';

    EtoCKroger TestEtoCKroger=new EtoCKroger ();
    TestEtoCKroger.handleInboundEmail(email, env);
    Messaging.InboundEmailResult result = TestEtoCKroger.handleInboundEmail(email, env);
    System.assertEquals( result.success , true);

    Case[] c = [select id, SVMXC__site__r.id, SVMXC__Site__c, recordtypeid, KA_PO__c, Location_Contact_Name__c, description, BSP_Location_Contact_Phone__c, subject, Case_Type__c, Origin, Status, Account.Name, account.id from Case where SVMXC__Site__c = :loc.Id limit 1];
    system.debug('TestEtoCKroger: [' + TestEtoCKroger + ']' );

    if(c.size() > 0)

    System.assertEquals(c[0].SVMXC__Site__c, loc.Id);
    System.assertEquals(c[0].account.Id, acc.Id);
    System.assertEquals(c[0].recordtypeId, 'rtId');
    System.assertEquals(c[0].KA_PO__c, '1001');
    System.assertEquals(c[0].Location_Contact_Name__c, 'Test Man');
    System.assertEquals(c[0].BSP_Location_Contact_Phone__c, '111 222 3443');
    System.assertEquals(c[0].subject, 'Test Subject');
    System.assertEquals(c[0].Case_Type__c, 'Service Request');
    System.assertEquals(c[0].Origin, 'Email');
    System.assertEquals(c[0].Status, 'New');
    System.assertEquals(c[0].description, 'Test description');
    update c;

    }

    }

  • APEX CLASS:

    *** Apex Email services class***

    global Class EtoCkroger implements Messaging.InboundEmailHandler {

    // Instantiate variables that we will need for handling this email

    String location;
    String problem;
    Integer locationIdx;
    Integer problemIdx;
    String locationFinal;
    String needFinal;
    String serviceFinal;
    String tradeFinal;
    String InboxFinal;
    String initiatorFinal;
    String TimeFinal;
    String poFinal;
    String phoneFinal;
    String warrantyFinal;
    String descriptionFinal;
    String orderFinal;
    String criticalFinal;
    String productFinal;
    String problemFinal;
    String machineFinal;
    String krogerFinal;
    String siteFinal;
    global Messaging.InboundEmailResult handleInboundEmail
    (Messaging.InboundEmail email, Messaging.InboundEnvelope envelope){
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    if (email.fromaddress =='[email protected]') //// Kroger locations
    {

    String[] bodySplitted = email.PlainTextBody.split('n');

    krogerFinal = email.subject.substringAfter(')').normalizespace();
    poFinal = email.plainTextBody.substringBetween('Call/Action #' , 'Call/Action Type/Status').remove('*').remove('(Include this # on Invoice)').normalizespace();
    initiatorFinal = email.plainTextBody.substringBetween('Point of Contact', 'Billing Address').remove('*').normalizespace();
    tradeFinal = email.plainTextBody.substringBetween('Symptom' , 'Notes').remove('*').normalizespace();
    problemFinal = email.plainTextBody.substringBetween('Notes' , 'Service Window').remove('*').remove('Service Requirements:').normalizespace();
    criticalFinal = email.plainTextBody.substringBetween('Severity' , 'Service').remove('*').normalizespace();
    productFinal = email.plainTextBody.substringBetween('Product' , 'Symptom').remove('*').trim();
    orderFinal = email.plainTextBody.substringBetween('Service Window' , 'Start Date/Time').remove('*').normalizespace();
    inboxFinal = email.plainTextBody.substringBetween('Start Date/Time' , 'Respond By').remove('*').normalizespace();
    timeFinal = email.plainTextBody.substringBetween('Respond By' , 'Complete By').remove('*').normalizespace();
    needFinal = email.plainTextBody.substringBetween('Complete By' , 'Please open').remove('*').remove('Special Instructions:').remove('-').normalizespace();
    descriptionfinal = 'Product: ' + productFinal + 'n' + 'Service Window: ' + orderFinal + 'n' + 'Start Date/Time: ' + inboxFinal + 'n' + 'Respond By: ' + timeFinal + 'n' + 'Complete By: ' + needFinal;

    Map<ID,Schema.RecordTypeInfo> rt_Map = Case.sObjectType.getDescribe().getRecordTypeInfosById();
    Id RecordTypeIdCase = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Service - Managed Service Case').getRecordTypeId();
    Id rtId = RecordTypeIdCase;

    system.debug('productFinal: ' +productFinal);
    system.debug('tradeFinal: ' +tradeFinal);
    system.debug('poFinal: ' +poFinal);
    system.debug('orderFinal: ' +orderFinal);
    system.debug('krogerFinal: ' +krogerFinal);
    system.debug('problemFinal: ' +problemFinal);
    system.debug('initiatorFinal: ' +initiatorFinal);
    system.debug('descriptionfinal: ' +descriptionfinal);
    if (krogerFinal != NULL) {
    SVMXC__Site__c [] locArray = [Select Id, Name, SVMXC__Site_Phone__c, SVMXC__Account__r.Id from SVMXC__Site__c where NTT_Legacy_Location_ID__c = :krogerFinal];
    try{

    case c= new case();
    c.subject= 'BUNNSERVE REQUEST';
    c.Case_Type__c= 'Service Request';
    c.Origin='Email';
    c.Status='new';
    c.AccountId = locArray[0].SVMXC__Account__r.Id;
    c.SVMXC__Site__c = locArray[0].Id;
    c.RecordTypeId = rtId;
    c.Description= 'Symptom: ' + tradeFinal + 'n' + 'Notes: ' + problemFinal + 'n' + 'Severity: ' + criticalFinal + + 'n' + descriptionfinal;
    c.KA_PO__c= poFinal;
    c.Location_Contact_Name__c = InitiatorFinal;
    c.BSP_Location_Contact_Phone__c = locArray[0].SVMXC__Site_Phone__c;
    c.OwnerId = '00G0x000000K0J3';

    insert c;
    }
    catch(System.dmlException e)
    {System.debug('Error: Unable to create new Case: ' + e);
    }

    }
    else if (krogerFinal == null){
    System.debug('No location was found');
    }

    }
    return result;

    } // Close handleInboundEmail ()
    }

  • Shashank

    Member
    August 9, 2018 at 6:51 pm in reply to: How to create child cases from custom case numbers in Salesforce?

    Let me explain it precisely. We are supposed to create cases for our customers through vf page for quality issues related to their products. We have different functional areas such as Design, Quality etc., For ex, customer A has a issue related to his product design, we create a case, say the case number is (QR-121). That issue is resolved and case will be closed. Customer has another product which has the same issue with product design in the near future. so, we create a case (QR-145). Since there's a similar case resolved earlier, we want to use that case as a reference. I've a look up field to case to add the reference case (QR 121), but when I try to look up for QR 121, it obviously won't show any records, as the lookup is associated with the standard case number. How can I be able to add reference cases by it's custom case number (QR 121) instead of the standard case number?

  • Is there any way to restrict the access to only first two sections to whoever creates the case in the visual-force page? Like, I've a custom button to vf page called as Quality report,  in Case layout. I want only two sections visible to the user who creates the case by clicking on the custom button. According to recent update for my requirement, any of the three profiles can create a case.

  • Any help guys?

  • Hello Jean, Thank you so much for the help.

Popular Salesforce Blogs