• Priyadarshini Manoharan 3
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 21
    Replies
I want the trigger code to be executed only for a Community User profile. An if condition to check if the feed item created by user has community profile. This if condition is causing the test class to lose coverage from 100% to 47%.
I added System.runAs for community user profile for entrie code. However there is no change in coverage.
Trigger
trigger EmailonChatterPostbyCustomer on FeedItem (after insert, after update) 
{
 
       List<EntitySubscription> stEntitySubList = new List<EntitySubscription>();
       Set<Id> CaseIds = new Set<Id>();
       Set<Id> OwnerIds = new Set<Id>();
 
        for (FeedItem f: trigger.new) 
        {
              Profile p = [SELECT Id, Name FROM Profile WHERE Name='DPS Customer Community'];
              if(f.CreatedBy.Profile.Name == p.Name)
              {
                CaseIds.add(f.ParentId);
              }
                  
        }
             
             List<Case> ca = new List<Case>([SELECT Id,CaseNumber,OwnerId,Owner.Name,Owner.Type FROM Case where id in :CaseIds and DPSProduct__c != 'ConnectMe']);
            
            
             
            /*for(Case c : ca)
            {
                if(c.Owner.Type=='User')
                {
                
                    c.Customer_Posted_on_Chatter__c = true;
                }
                       
            }
            update ca;*/
            
                DPSCustomSetting__c mbox = DPSCustomSetting__c.getInstance();
                string mailbox = mbox.DefaultMailBox__c;
  
                OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address =: mailbox];
                
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                if ( owea.size() > 0 ) 
                {    mail.setOrgWideEmailAddressId(owea.get(0).Id);}
                
                
                
                List<EntitySubscription> followers = [select id, subscriberid, subscriber.name, subscriber.email, parentid from EntitySubscription where parentid in :CaseIds];
    
                System.debug('***id subscriberid subscriber.name subscriber.email' + followers);
    
    
                String[] toAddresses = new List<String>();
                String[] toUserId = new List<String>();
                
                 if(followers.size() > 0)
                 {
                    /* for(Case c : ca)
                        {
                            if(c.Owner.Type=='User')
                            {
                            
                                c.Customer_Posted_on_Chatter__c = true;
                            }
                                   
                        }
                        update ca; 
                        */ 
                    
                                        
                    for (EntitySubscription follower : followers)
                    {
                        toAddresses.add(follower.subscriber.email);
                        toUserId.add(follower.subscriberid);
                    }
               
                
                    EmailTemplate et = [Select id from EmailTemplate where name = 'Customer Posts on Case Chatter Feed'];
                 
                    for(EntitySubscription es : followers)
                    {
                       
                       mail.setToAddresses(toAddresses);
                     
                         mail.setTargetObjectId(es.subscriberid);
                         mail.setWhatId(es.parentid);                   
                         mail.setTemplateID(et.Id);
                         System.debug('*****toAddresses' + toAddresses);        
                         mail.setSaveAsActivity(false);              
                    } 
                
                    if(mail != null ) 
                    {
                        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); 
                       for(Case c : ca)
                        {
                            if(c.Owner.Type=='User')
                            {
                            
                                c.Customer_Posted_on_Chatter__c = true;
                            }
                                   
                        }
                        update ca;            
                    }    
                         
                 }
                
}

Test Class

@isTest(SeeAllData=true)
public class TestEmailonChatterPostbyCustomer
{
    static testMethod void EmailonChatterPost()
    {
    
   // User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    
    // System.runAs (thisUser) 
    // {
    Account portalAccount1 = new Account(
    Name = 'TestAccount' );
    insert portalAccount1;
    
    Contact contact1 = new Contact(
    FirstName = 'Test',
    Lastname = 'McTesty',
    AccountId = portalAccount1.Id,
    Email = 'test@test.com'
    );
    insert contact1;
       
       
       
       String uniqueUserName = 'portaluser' + DateTime.now().getTime() + '@testorg.com';
        // This code runs as the system user
        Profile pro = [SELECT Id FROM Profile WHERE Name='DPS Customer Community'];
        User uid = new User(Alias = 'standt', Email='standarduser@testorg.com',
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
        LocaleSidKey='en_US', ProfileId = pro.Id,
        TimeZoneSidKey='America/Los_Angeles',ContactId = contact1.Id,
         UserName=uniqueUserName);
         insert uid;
         
          User us = new User();
        String ProfileId=[Select Id,Name from Profile where Name='System Administrator'].Id;
        us.FirstName = 'Support Agent';
        us.LastName  = 'DPS';
        us.Email     = 'dps@deloitte.com';
        us.Username  = 'dps@support.com';
        us.Alias     = 'ddps';
        us.ProfileId = ProfileId;
        us.Product__c = 'Revenue Intellect';
        us.Product_Access__c = 'Revenue Intellect User';
        us.TimeZoneSidKey    = 'America/Denver';
        us.LocaleSidKey      = 'en_US';
        us.EmailEncodingKey  = 'UTF-8';
        us.LanguageLocaleKey = 'en_US';
        
        insert us;
        
        
      System.runAs(uid) 
        
       {
               
            Account Acc = new Account();
            Acc.Name ='Bank of America';
            Acc.Sold_To_Flag__c = true;
            insert Acc;
            Case c = new Case(AccountId=Acc.Id, DPSIssue_Type__c= 'Data' ,Priority= 'High', DPSReason__c= 'Data question', DPSProduct__c = 'Revenue Intellect');
            insert c;
          
       // c.OwnerId = us.Id;
       // c.Customer_Posted_on_Chatter__c = true;
       // update c;
        
      /*  Profile p = [select id from profile where Name = :'System Administrator' limit 1];
        User pu = new User(profileId = p.id, username = 'tt@ff.com', email = 'pp@cc.com',
        emailencodingkey = 'UTF-8', localesidkey = 'en_US',
        languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
        alias='cspu', lastname='lastname');
        insert pu;


        EntitySubscription es = new EntitySubscription ( ParentId = c.id, SubscriberId = pu.Id);
        insert es;*/
        
        System.debug('UserInfo.getProfileId()' + UserInfo.getProfileId());
       
            FeedItem feed = new FeedItem (ParentId = c.id,Body = 'Hello', type = 'TextPost');
            insert feed;
      }
    // }  
        
    }
    
    static testMethod void EmailonChatterPost1()
    {
   
          User us = new User();
        String ProfileId=[Select Id,Name from Profile where Name='System Administrator'].Id;
        us.FirstName = 'Support Agent1';
        us.LastName  = 'DPS1';
        us.Email     = 'dps1@deloitte.com';
        us.Username  = 'dps1@support.com';
        us.Alias     = 'ddps';
        us.ProfileId = ProfileId;
        us.Product__c = 'Revenue Intellect';
        us.Product_Access__c = 'Revenue Intellect User';
        us.TimeZoneSidKey    = 'America/Denver';
        us.LocaleSidKey      = 'en_US';
        us.EmailEncodingKey  = 'UTF-8';
        us.LanguageLocaleKey = 'en_US';
        
        insert us;
        
        
     
               
            Account Acc = new Account();
            Acc.Name ='Bank of America';
            Acc.Sold_To_Flag__c = true;
            insert Acc;
            Case c = new Case(AccountId=Acc.Id, DPSIssue_Type__c= 'Data' ,Priority= 'High', DPSReason__c= 'Data question', DPSProduct__c = 'Revenue Intellect');
            insert c;
          
        c.OwnerId = us.Id;
        c.Customer_Posted_on_Chatter__c = true;
        update c;
        
        Profile p = [select id from profile where Name = :'System Administrator' limit 1];
        User pu = new User(profileId = p.id, username = 'tt@ff.com', email = 'pp@cc.com',
        emailencodingkey = 'UTF-8', localesidkey = 'en_US',
        languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
        alias='cspu', lastname='lastname');
        insert pu;


        EntitySubscription es = new EntitySubscription ( ParentId = c.id, SubscriberId = pu.Id);
        insert es;
        
        System.debug('UserInfo.getProfileId()2' + UserInfo.getProfileId());
       
            FeedItem feed = new FeedItem (ParentId = c.id,Body = 'Hello', type = 'TextPost');
            insert feed;
      
       
        
    }
}
I have a Visualforce email template with recipient type as User and
relatedtoType as case. I am able to access Chatter Post in email as below. However I am not able to access the Chatter FeedComment in the email template as it is based on a different object which is a child of CaseFeed. What is the relatedTo value for FeedComments on the Case object for Visualforce email templates or how do I access grand child object FeedComments in Visualforce email template for relatedToType = Case
</table>



<h1 style="font-size:100%">Case Feed:</h1>

<table border="1">
<tr>
<th> Date/Time </th>
<th> Created By </th>
<th> Chatter Post </th>


</tr>



<apex:repeat var="cx" value="{!relatedTo.Feeds}">
               
<tr>
<td>{!cx.CreatedDate} </td>
<td>{!cx.CreatedBy.Name}</td>
<td>{!cx.Body}</td>


</tr>

</apex:repeat>
</table>

 
I want to create a custom email template (preferrably visualforce) for Chatter Feed email with merge field body
Duplicate rules not firing when the logged in user profile does not have access to the lead record created by System Admin and the user is creating a duplicate of this system admin lead record
When Lead Conversion is done by clicking the Convert button by another profile other than System Admin and if the Lead Owner is a Queue it fails with the below error
ConvertLead failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
Error is in expression '{!convertLead}' in component <apex:commandButton> in page leadconvertpage: Class.leadConvertController.convertLead: line 156, column 1

An unexpected error has occurred. Your development organization has been notified.
 
The issue was introduced as when we had queue being assigned in Lead Assignment Rule. We have custom code on Lead Convert button which tries to create a new Contact with the Lead Owner Id, it is unable to create a new contact with Lead Owner Id as the Lead Owner is a queue. I want to display custom error message and overcome this error. However the error gets fired still.
The "chosen" section for multi select picklist field extends well beyond the box. How to increase the width of multi select picklist window? os that the chosen section is well within the multi select picklist window. This is in Opportunity standard salesforce Page Layout.
How to update a multi-select picklist field at Lead level from a multi-select picklist field at Campaign Level? when the multi-select picklist field at Lead level is blank
Getting error Modules: Validation Error: Value is not valid on custom VF page for dependent picklist. 
somehow the controlling and dependent picklist values fetched disappear when the submit button is clicked
Contact Lookup filter search not working for existing Contacts. If we search on name of Contact, it does not retrieve the Contact though it exists.
Hi,

This is nothing salesforce technical:) I would like to know how do I get alerts on questions posted in this salesforce developers forum?

Thanks and Regards
Priya
Say a customer community ABC has 2 customers A and B, and A and B have seperate profile and role and visibility rules set up such that they dont see each others records(Cases, Account, Contact and some custom objects). The question is now if we have a new community say PQR and we want B customer and his associated records to be moved to community PQR. This would also mean that we need to remove B and its associated records from ABC customer. How can the last 2 statements be achieved?

Thanks and Regards
Priya

Hi All,

In Entitlement managent, once it is activated, there is an option to expose Timeline field at Case level. This field graphically depicts the milestone timelines, with an adjustable zoom. Can any explain how it shows the Case Milestones apart from what is mentioned in the Salesforce entitlement management document.

Timeline field image
Thanks and Regards
PD

 

Can we compare 2 multi-select picklist fields in a formula field? If so how?
Here's the code, inputValue from apex page should be assigned to webcase.Product__c

Apex page

<apex:page standardController="Case" extensions="CaseStdControllerExt" title="Contact Us" showHeader="true" standardStylesheets="true" docType="html-5.0">


<apex:form id="frm">
    <apex:pageBlock title="Enter Case Details" rendered="true">
        <apex:pageBlockButtons >
        <apex:commandButton value="Submit Case" action="{!savecase}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Case Information" collapsible="false" columns="1">
        <apex:inputField value="{!Case.Product__c}"  id="inptID" onchange="MyjavaFunction('{!$Component.inptID}')" />
       
       

        <apex:inputField value="{!Case.Description}"  id="casedesc"/>
        </apex:PageBlockSection>
    </apex:pageBlock>
</apex:form>

 <!-- Java script starts Here -->
  <script>
   function MyjavaFunction(ReceiveInputID){
  
    var inputValue = document.getElementById(ReceiveInputID).value;
         if(inputValue == ''){
            alert('You did not eneter any value in input box');
         }
         else
         {
            alert(' You entered :: '+inputValue);
         }
           
           
   }
  </script>
</apex:page>

Standard Extension controller

public class CaseStdControllerExt {

private final Case webcase;

    public CaseStdControllerExt(ApexPages.StandardController controller) {
    
    webcase = (Case)controller.getRecord();

    }
    
     public PageReference savecase() 
     {
       

       upsert(webcase);
       PageReference p = new ApexPages.StandardController(webcase).view();
       p.setRedirect(true);
       return p;
       
     }

}

 
There is a picklist field on a VF page, after clicking on new button once I select a picklist value in the field, how do I fetch the value, before it is saved in the database. I need to use this fetched value to populate another field before the record is saved.
To explain the scenario will make the example simple say if I have a picklist field Issue Type on Case which has values Access, Performance, Request etc.
There is another field Description which is a long text/rich text which needs to be pre-defaulted based on the value selected from the Issue Type field.
Issue Type and Description are fields on VF page with standard controller case
If Issue Type = Access, Description should be Please include full name and email address
If Issue Type = Performance, Description should be Detail when the problem started, specific error messages, performance now vs. before (benchmarks), application name (and environment if applicable) and browser
If Issue Type =  Request, Description should be Include application name, desired feature, details on use case
 
The "chosen" section for multi select picklist field extends well beyond the box. How to increase the width of multi select picklist window? os that the chosen section is well within the multi select picklist window. This is in Opportunity standard salesforce Page Layout.
How to update a multi-select picklist field at Lead level from a multi-select picklist field at Campaign Level? when the multi-select picklist field at Lead level is blank

Hi All,

In Entitlement managent, once it is activated, there is an option to expose Timeline field at Case level. This field graphically depicts the milestone timelines, with an adjustable zoom. Can any explain how it shows the Case Milestones apart from what is mentioned in the Salesforce entitlement management document.

Timeline field image
Thanks and Regards
PD

 

Can we compare 2 multi-select picklist fields in a formula field? If so how?
Here's the code, inputValue from apex page should be assigned to webcase.Product__c

Apex page

<apex:page standardController="Case" extensions="CaseStdControllerExt" title="Contact Us" showHeader="true" standardStylesheets="true" docType="html-5.0">


<apex:form id="frm">
    <apex:pageBlock title="Enter Case Details" rendered="true">
        <apex:pageBlockButtons >
        <apex:commandButton value="Submit Case" action="{!savecase}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Case Information" collapsible="false" columns="1">
        <apex:inputField value="{!Case.Product__c}"  id="inptID" onchange="MyjavaFunction('{!$Component.inptID}')" />
       
       

        <apex:inputField value="{!Case.Description}"  id="casedesc"/>
        </apex:PageBlockSection>
    </apex:pageBlock>
</apex:form>

 <!-- Java script starts Here -->
  <script>
   function MyjavaFunction(ReceiveInputID){
  
    var inputValue = document.getElementById(ReceiveInputID).value;
         if(inputValue == ''){
            alert('You did not eneter any value in input box');
         }
         else
         {
            alert(' You entered :: '+inputValue);
         }
           
           
   }
  </script>
</apex:page>

Standard Extension controller

public class CaseStdControllerExt {

private final Case webcase;

    public CaseStdControllerExt(ApexPages.StandardController controller) {
    
    webcase = (Case)controller.getRecord();

    }
    
     public PageReference savecase() 
     {
       

       upsert(webcase);
       PageReference p = new ApexPages.StandardController(webcase).view();
       p.setRedirect(true);
       return p;
       
     }

}

 
There is a picklist field on a VF page, after clicking on new button once I select a picklist value in the field, how do I fetch the value, before it is saved in the database. I need to use this fetched value to populate another field before the record is saved.

I'm trying to copy a new user as contact by using a trigger but I'm getting the following error

 

MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User

 

trigger Acceleration_User_Copyto_Contact on User (after insert, after update) {
    
   // Map<String,User> newLead = new Map <String, User>();
    
    system.debug('Acceleration_User_Copyto_Contact Trigger....');
 
    for ( User user : System.Trigger.new)
    {
        if  (user.Email.contains('acceleration'))
        {
            system.debug('Acceleration_User_Copyto_Contact Trigger..2.');
            Integer RecordCount = [select count() from Contact c where c.Email = : user.Email];
            
            system.debug('Acceleration_User_Copyto_Contact Trigger..2a .' + RecordCount);
            
            if (RecordCount == 0)
            {
                String AccountId = '';
                for ( Account a : [Select a.Id From Account a where Name = 'Acceleration']) 
                {
                    system.debug('Acceleration_User_Copyto_Contact Trigger..3.');
                     
                    AccountId = a.Id;
                
                    Contact con = New Contact();
                    con.AccountId = AccountId ;
                    con.Email = user.Email;
                    con.Firstname = User.Firstname;
                    con.Lastname = User.Lastname ;
                    con.User__c = User.Id;
                    insert con;
                }          
            }                   
        }
        
     }
    
    
}