• xNamelessonex
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
I have the following Class which was created under a sandbox environment, following the tutorial from this guide https://developer.salesforce.com/page/An_Introduction_To_Email_Services_on_Force.com:
 
global  class CaseCommentReply implements Messaging.InboundEmailHandler {

    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, 
                                                           Messaging.Inboundenvelope envelope )
        
    {
       
    
      Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();  
        
        try
    {
        
        
        
        Id csId = Cases.getCaseIdFromEmailThreadId(email.subject.substringBetween('ref:', ':ref'));
        
        System.debug('CaseId Value'+ csId);
        
        if (csId != null)
        {
            
            String TextStrip = email.plainTextBody;
            
            
            
           CaseComment comment = new CaseComment(ParentId = csId,CommentBody = TextStrip.substringBefore('--Reply above this line--'),isPublished = true); 
            
            insert comment; 
            
            System.debug('The comment of the case with the Id '+comment.ParentId+ 'has been updated \n The text: \n'+comment.CommentBody);
            result.success = true; 
            
            
        }
        
    }   
      catch(Exception e)
      {
          System.debug('An exception ocurred while attempting to create a comment from Email  '+e);
           System.debug('There were errors while processing the function');
          result.success = false; 
          
      }
        
        
        if (result.success == true)
        {
        System.debug('The function has processed correctly');
        }
         
            
         
        return result; 
        
    }
    
  
    
    
    
    
    
}

And the Test Class:
 
@isTest
public class CaseCommentReplyTest {

    
   
    static testMethod void TestEmailToComment()
    {    
    
        
        Case testCase = new Case();
         insert testCase; 
        String caseId = testCase.Id;
        System.debug('Value of the case id'+caseId);
       
        
        string Case_ThreadID = '_'  + UserInfo.getOrganizationId().left(4)  + '0'  + UserInfo.getOrganizationId().mid(11,4) + '._'  + caseId.left(4) + '0'  + caseId.mid(10,5);
        
        Messaging.InboundEmail email = new Messaging.InboundEmail();
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        
        email.plainTextBody = 'Test';
        email.subject = 'Re: Sandbox: Case. [ ref:'+Case_ThreadID+':ref ]'; 
        
        Messaging.InboundEmail exceptionEmail = new Messaging.InboundEmail();
        
        
        
       Test.startTest();
       CaseCommentReply crep = new CaseCommentReply();
        
        crep.handleInboundEmail(email,env); 
        crep.handleInboundEmail(exceptionEmail, env);
        
    Test.stopTest();
    
    }
    
}

When I created the Email Service, the user for the Context User, under the Email address associated to the Email Service is a Super User, with full priviledges on the organization. It is the same user as the Email Service from the Sandbox. And the configuration of the Email service is the same. Is there any configuration I might be missing under the production environment which triggers the Error:

"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY" When Inserting the Comment into Salesforce? 

 
I have read some posts on the forum, which use this as a demonstration of how to create good code coverage. http://amitsalesforce.blogspot.mx/2015/06/best-practice-for-test-classes-sample.html


I am using the Force.com Developer console, and when running tests the code coverage goes up to 40% or less, sometimes changing by 2%. The code not covered, according to the console has the following format:


 
if(Database.countQuery('SELECT count() FROM User WHERE User.Id = \''+ Object.variable+'\'') > 0)
             usr.add(Database.query('SELECT Id,Email FROM User WHERE User.Id = \''+ Object.variable +'\''));
Now how do have to code this from the test perspective? I have created SObjects accordingly in the test class, but even if I do, the console does not increase the code coverage for the class intended to be set in production.


 
I am trying to access data generated in the Napili Template through apex but I haven't found a way to get said information.

Particularly what I would like to manipulate through programming is the list of users in a given group. The visibility of the cases created in the Template.

Is it possible to achieve this through programming? Or is there a workaround to get the information, when this is created through the Napili template's GUI?

Trying to figure out a way through the clickfest known as salesforce GUI, is quite hard, an apex based solution would be prefered. 
First of all, I would like to apologize for such a newb question, but google has given me no insights. What I would like to do is create a navigation menu, which upon clicking one of it's elements would show a lightning component within the page itself.

Basically I want to integrate a lightning component into the website itself, without redirecting to another new page, same as shown in this tutorial. http://jargon.io/salesforcejeff/iframecomponent As far as I have been able to do with the tutorial itself, it is possible to add a lightning component to a tab. However I would like to do the exact same thing but with one of the options of the navigation bar.

The question is, can this actually be done through the community builder or would this require me to write everything from scratch, in either force.com or site.com; disregarding the napili template provided by salesforce? 
I have read some posts on the forum, which use this as a demonstration of how to create good code coverage. http://amitsalesforce.blogspot.mx/2015/06/best-practice-for-test-classes-sample.html


I am using the Force.com Developer console, and when running tests the code coverage goes up to 40% or less, sometimes changing by 2%. The code not covered, according to the console has the following format:


 
if(Database.countQuery('SELECT count() FROM User WHERE User.Id = \''+ Object.variable+'\'') > 0)
             usr.add(Database.query('SELECT Id,Email FROM User WHERE User.Id = \''+ Object.variable +'\''));
Now how do have to code this from the test perspective? I have created SObjects accordingly in the test class, but even if I do, the console does not increase the code coverage for the class intended to be set in production.


 
I have the following Class which was created under a sandbox environment, following the tutorial from this guide https://developer.salesforce.com/page/An_Introduction_To_Email_Services_on_Force.com:
 
global  class CaseCommentReply implements Messaging.InboundEmailHandler {

    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, 
                                                           Messaging.Inboundenvelope envelope )
        
    {
       
    
      Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();  
        
        try
    {
        
        
        
        Id csId = Cases.getCaseIdFromEmailThreadId(email.subject.substringBetween('ref:', ':ref'));
        
        System.debug('CaseId Value'+ csId);
        
        if (csId != null)
        {
            
            String TextStrip = email.plainTextBody;
            
            
            
           CaseComment comment = new CaseComment(ParentId = csId,CommentBody = TextStrip.substringBefore('--Reply above this line--'),isPublished = true); 
            
            insert comment; 
            
            System.debug('The comment of the case with the Id '+comment.ParentId+ 'has been updated \n The text: \n'+comment.CommentBody);
            result.success = true; 
            
            
        }
        
    }   
      catch(Exception e)
      {
          System.debug('An exception ocurred while attempting to create a comment from Email  '+e);
           System.debug('There were errors while processing the function');
          result.success = false; 
          
      }
        
        
        if (result.success == true)
        {
        System.debug('The function has processed correctly');
        }
         
            
         
        return result; 
        
    }
    
  
    
    
    
    
    
}

And the Test Class:
 
@isTest
public class CaseCommentReplyTest {

    
   
    static testMethod void TestEmailToComment()
    {    
    
        
        Case testCase = new Case();
         insert testCase; 
        String caseId = testCase.Id;
        System.debug('Value of the case id'+caseId);
       
        
        string Case_ThreadID = '_'  + UserInfo.getOrganizationId().left(4)  + '0'  + UserInfo.getOrganizationId().mid(11,4) + '._'  + caseId.left(4) + '0'  + caseId.mid(10,5);
        
        Messaging.InboundEmail email = new Messaging.InboundEmail();
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        
        email.plainTextBody = 'Test';
        email.subject = 'Re: Sandbox: Case. [ ref:'+Case_ThreadID+':ref ]'; 
        
        Messaging.InboundEmail exceptionEmail = new Messaging.InboundEmail();
        
        
        
       Test.startTest();
       CaseCommentReply crep = new CaseCommentReply();
        
        crep.handleInboundEmail(email,env); 
        crep.handleInboundEmail(exceptionEmail, env);
        
    Test.stopTest();
    
    }
    
}

When I created the Email Service, the user for the Context User, under the Email address associated to the Email Service is a Super User, with full priviledges on the organization. It is the same user as the Email Service from the Sandbox. And the configuration of the Email service is the same. Is there any configuration I might be missing under the production environment which triggers the Error:

"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY" When Inserting the Comment into Salesforce? 

 
I have read some posts on the forum, which use this as a demonstration of how to create good code coverage. http://amitsalesforce.blogspot.mx/2015/06/best-practice-for-test-classes-sample.html


I am using the Force.com Developer console, and when running tests the code coverage goes up to 40% or less, sometimes changing by 2%. The code not covered, according to the console has the following format:


 
if(Database.countQuery('SELECT count() FROM User WHERE User.Id = \''+ Object.variable+'\'') > 0)
             usr.add(Database.query('SELECT Id,Email FROM User WHERE User.Id = \''+ Object.variable +'\''));
Now how do have to code this from the test perspective? I have created SObjects accordingly in the test class, but even if I do, the console does not increase the code coverage for the class intended to be set in production.