• Susheel Reddy B
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 9
    Replies
I have onclick JavaScrupt button in Listview and it passes the selected recordid's to VF page. I am using this in Lightening App. When I submitted my app to security review, i got the below response

"JavaScript of any type is not allowed to run within the Salesforce.com application context. This includes JavaScript blocks within HomePageComponents, WebLinks, and all other components that are run under the Salesforce.com DOM."
Hi,

I have issues in writing test class for below copntroller.
 
public class EditContacts {

    ApexPages.StandardSetController setCon;
    List<string> strIds = new List<string>();
    List<Contact> lstContact = new List<Contact>();
    public integer size {get;set;}
    public final String URL {get;set;}
    public Contact c;
    
    public Contact getNewContact()
    {
      if(c==null)c= new Contact();
      return c;
    }
    public MassEditContacts (Apexpages.Standardsetcontroller cont)
    {
        setCon = cont;
        strIds = ApexPages.currentPage().getParameters().get('recs').split(',',-2);
        size = strIds.size();
        URL = ApexPages.currentPage().getURL();
    
    }
    public List<Contact> getContacts()
    {
        lstContact = [select Name, Title, Phone, MobilePhone, Email, AccountId, ownerid from Contact where id IN: strIds ];
        return lstContact;
    }
     
    public Pagereference saveRecords()
    {
        List<Contact> updateContact = new List<Contact>();
    for(Contact cse : lstContact)
    {
      updateContact.add(cse);
    }
        update updateContact;
        return new Pagereference('/'+Contact.getSObjectType().getDescribe().getKeyPrefix()+'/o');
    }
    
    public Pagereference ccancel()
    {
        system.debug('***ccancel**');
        return new Pagereference('/'+Contact.getSObjectType().getDescribe().getKeyPrefix()+'/o');
    }
}

 

Hi,

 

In Email-to-Case if any person sends an email to Email routing address with other email id's in To, Cc or Bcc fields, then we need to send an acknowledgement email to all those email addresses in To, Cc or Bcc fields.

 

I wrote a trigger on Email object to get To, CC and Bcc fields, it's working fine for To,Cc fields but unable to get Bcc field.

When there is single email id in To or Cc field, i am able to send auto acknowledgement email but when there is multiple emails unbale to send emails using Outbond Email method.

 

Please suggest me the best possible way.

 

Please find the below code :

 

trigger testToCcBccAddress on EmailMessage (after insert) {
List<Case> cases = new List<Case>();
for (Integer i = 0; i < Trigger.new.size(); i++ )
{
try
{
Case c = new Case();
c=[SELECT id, Description,Subject, CaseNumber,RecordTypeId,To_Address__c,Cc_Address__c,Bcc_Address__c,Case_Thread_ID__c FROM Case WHERE Id = :Trigger.new[i].ParentId];
if(Trigger.new[i].ToAddress!= null && c.To_Address__c == null && Trigger.new[i].CcAddress == null)
{
c.To_Address__c= Trigger.new[i].ToAddress;
}
if(Trigger.new[i].CcAddress!= null && c.Cc_Address__c == null && Trigger.new[i].ToAddress == null)
{
c.Cc_Address__c= Trigger.new[i].CcAddress;
}
if(Trigger.new[i].ToAddress!= null && c.To_Address__c == null && Trigger.new[i].CcAddress!= null && c.Cc_Address__c == null)
{
c.To_Address__c= Trigger.new[i].ToAddress;
c.Cc_Address__c= Trigger.new[i].CcAddress;
}
cases.add(c);
update cases;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();{
String emailtoAddr = [select To_Address__c from Case Case WHERE Id = :Trigger.new[i].ParentId].To_Address__c;
String emailCcAddr = [select Cc_Address__c from Case Case WHERE Id = :Trigger.new[i].ParentId].Cc_Address__c;
system.debug('******* TO Address ******'+emailtoAddr);
system.debug('******* CC Address ******'+emailCcAddr);
if (emailtoAddr != null)
{
emailtoAddr = emailtoAddr.replace(';\n', ', ');
String[] toAddresses = new String[] {emailtoAddr};
system.debug('****** To Address *******'+toAddresses);
mail.setToAddresses(toAddresses);
}
if (emailCcAddr != null)
{
emailCcAddr = emailCcAddr.replace(';\n', ', ');
String[] ccAddresses = new String[] {emailCcAddr};
system.debug('****** Cc Address *******'+ccAddresses);
mail.setCcAddresses(ccAddresses);
}
// String[] toAddresses = new String[] {'susheel.tecnics@yahoo.com','susheel_reddy@tecnics.com'};
// String[] ccAddresses = new String[] {'susheel.tecnics@yahoo.com','susheel_reddy@tecnics.com'};
if (c.RecordTypeId == '01290000000OPJp')
{
OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress where DisplayName= 'Tecnics Consultng Inc.'];
mail.setOrgWideEmailAddressId(owa.id);
}
if (c.RecordTypeId == '01290000000OPJk')
{
OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress where DisplayName= 'Tecnics Integration Technologies'];
mail.setOrgWideEmailAddressId(owa.id);
}
mail.setSubject(c.Subject+' - ' +c.CaseNumber );
mail.setPlainTextBody('Dear Customer \n Case created : '+c.CaseNumber +'\n \n Regards \n Tecnics Consulting Inc \n \n ' +c.Case_Thread_ID__c );
mail.setHtmlBody('Dear Customer<br/><br/> Case Createdd - '+c.CaseNumber+' <br/> <br/> Regards<br/>Tecnics Consulting Inc <br/> <br/> '+c.Case_Thread_ID__c);
system.debug('****** Email *******'+mail);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
catch(exception e)
{
system.debug('*******'+e);
}
}
}

 

 

 

Thanks in advance.

Susheel Reddy

 

 

Hi All,

 

We have a after insert trigger on EmailMessage object to Capture "To Email address" (routing address) in Email To Case(We have 10 routing address).

Whenever a Case gets created from Email to Case, in case history it shows like this.

 

        10/3/2012 11:28 AM       Surander           Changed Owner (Assignment) from  Gallucci to Team1.  

                                                                               Changed Owner (Assignment) from  Surander to Galluci.                          

                                                                               Created.

 

But Surander is the Automated Case User, Gallucci is the Default owner of a case when assignment rules fail to locate an owner and Team1 is Queue.

 

But ideally it should not Change the Owner to Gallucci (If assignment rules locates an Owner for Case). 

If i inactive the trigger it is working fine, and Case history shows like this. 

 

      10/3/2012 11:28 AM        Surander             Changed Owner (Assignment) from  Surander to Team1.                            

                                                                                Created.

 

I need to write a workflow, when ever case owner is Gallucci, but for each and every Case workflow is firing because of the above issue.

 

Trigger Code:

 

trigger ToAddress on EmailMessage (after insert) {    
    List<Case> cases = new List<Case>();
    for (Integer i = 0; i < Trigger.new.size(); i++ )
    {          
        try
        {
        EmailMessage newEmail = Trigger.new[i];
        List<Case> c = [SELECT id, Description, caseNumber FROM Case WHERE Id = :newEmail.ParentId];
        if (c.size() > 0 ){            
        c[0].To_Address__c= newEmail.ToAddress;           
             update c;            
         }  
       }
       catch(exception e)
        {
            System.debug('***********'+e);
        }  
       }   
          update cases;
}

 

 

Please reply with any coding or configuration that will help in this regard.

Any help is much appreciated.

 

Regards,

Susheel Reddy

Hi,

I have issues in writing test class for below copntroller.
 
public class EditContacts {

    ApexPages.StandardSetController setCon;
    List<string> strIds = new List<string>();
    List<Contact> lstContact = new List<Contact>();
    public integer size {get;set;}
    public final String URL {get;set;}
    public Contact c;
    
    public Contact getNewContact()
    {
      if(c==null)c= new Contact();
      return c;
    }
    public MassEditContacts (Apexpages.Standardsetcontroller cont)
    {
        setCon = cont;
        strIds = ApexPages.currentPage().getParameters().get('recs').split(',',-2);
        size = strIds.size();
        URL = ApexPages.currentPage().getURL();
    
    }
    public List<Contact> getContacts()
    {
        lstContact = [select Name, Title, Phone, MobilePhone, Email, AccountId, ownerid from Contact where id IN: strIds ];
        return lstContact;
    }
     
    public Pagereference saveRecords()
    {
        List<Contact> updateContact = new List<Contact>();
    for(Contact cse : lstContact)
    {
      updateContact.add(cse);
    }
        update updateContact;
        return new Pagereference('/'+Contact.getSObjectType().getDescribe().getKeyPrefix()+'/o');
    }
    
    public Pagereference ccancel()
    {
        system.debug('***ccancel**');
        return new Pagereference('/'+Contact.getSObjectType().getDescribe().getKeyPrefix()+'/o');
    }
}

 
I have a class that uses the StandardSetController and I honestly have no clue what to do to get some decent code coverage on it.  I have written some basic parts of the test class, but can't figure out the rest.  Can someone help me understand what needs to be done with these kinds of test classes.

Here is the controller:
public with sharing class OutOfOffice {

    ApexPages.StandardSetController setCon;
    
    List<string> caseIds = new List<string>();
    
    List<Case> caseList = new List<Case>();
    
    public Case c;

    public Case getNewCase() {
    
        if(c == null){
            
            c = new Case();
        }
        
        return c;
    }
    
    public OutOfOffice (Apexpages.StandardSetController controller) {
    
        setCon = controller;
    
        caseIds = ApexPages.currentPage().getParameters().get('recs').split(',',-2);
    }
    
    public List<Case> getSelected() {
    
        caseList = [SELECT Subject,CaseNumber,Status FROM Case WHERE Id IN: caseIds];
    
        return caseList;
    }
    
    public Pagereference updateCases(){
    
        List<Case> updatedCases = new List<Case>();
        
        for(Case cse : caseList){
        
            cse.Out_Of_Office_Start__c = c.Out_Of_Office_Start__c;
            
            cse.Out_Of_Office_End__c = c.Out_Of_Office_End__c;
            
            cse.Out_Of_Office__c = c.Out_Of_Office__c;
            
            updatedCases.add(cse);
        }
        
        update updatedCases;

        return new Pagereference('/'+Case.getSObjectType().getDescribe().getKeyPrefix()+'?fcf='+ApexPages.currentPage().getParameters().get('retUrl'));
    }
    
    public Pagereference cancelUpdate(){

        return new Pagereference('/'+Case.getSObjectType().getDescribe().getKeyPrefix()+'?fcf='+ApexPages.currentPage().getParameters().get('retUrl'));
    }
}


Here is the current test class:
@isTest
private class OutOfOfficeTest{

    private static testmethod void testOutOfOffice() {
    
        // CREATE AND INSERT TEST CONTACT
        
        Contact con = new Contact (LastName = 'Smith', FirstName = 'Joe', Email = 'joesmith@test.com');
        
        insert con;
        
        
        // CREATE START AND END DATES
        
        Date startDate = date.today();
        
        Date endDate = startDate.addDays(1);
    
        
        // CREATE AND INSERT NEW CASE
        
        Case c = new Case(
        
            Out_Of_Office__c = true,
            Out_Of_Office_Start__c = startDate,
            Out_Of_Office_End__c = endDate,
            ContactId = con.Id
        );
        
        insert c;
    
        
        // CREATE AND INSERT NEW EMAIL
        
        EmailMessage em = new EmailMessage(
            FromAddress = 'test@example.com',
            Incoming = true,
            ToAddress = 'test@gmail.com',
            Subject = 'Test email',
            TextBody = 'Hello',
            ParentId = c.Id
        );
        
        insert em;
        
    
        // CREATE AND INSERT TEST CASE COMMENT
        
        CaseComment com = new CaseComment (
        
            CommentBody = 'test',
            ParentId = c.Id,
            IsPublished = true
        );    
        
        insert com;   
    }
}

I don't know where to go from here.

Please help!

Thanks ahead of time!!


I have placed a custom button on a Case List view.  The button, when clicked, needs to validate whether any case records were actually selected.  That part is done simply with a Javascript OnClick button with the following code:

{!REQUIRESCRIPT ("/soap/ajax/13.0/connection.js")} 

var selected = {!GETRECORDIDS($ObjectType.Case)}; 

if (selected[0] == null) { 

    alert("Please select at least one Case.")
} 

else {

     window.location = 'apex/MyPage';
}

The problem is that when validation passes (i.e. it goes to the MyPage visualforce page) the selected records aren't passed along.  Here is my VF page thus far:

<apex:page standardController="Case" recordSetVar="cases">
   <apex:form >
       <apex:pageBlock title="MyPage" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="MyButton"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Information" columns="2">
                <apex:inputCheckBox value="{!case.test__c}" selected="true" required="true"/>
                <apex:pageBlockSectionItem />
                <apex:inputField value="{!case.test2__c}" showDatePicker="true" required="true"/>
                <apex:inputField value="{!case.test3__c}" showDatePicker="true" required="true"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Selected Cases">
                <apex:pageBlockTable value="{!selected}" var="case">
                    <apex:column value="{!case.casenumber}"/>
                    <apex:column value="{!case.subject}"/>
                    <apex:column value="{!case.status}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>   
</apex:page>
The goal is to have the custom button on the List view validate whether records are checked, then when validation passes have those records displayed in the block table on the VF page.  I can get one or the other to work, but not both at the same time.  If I change the button to go directly to the VF page, the selected records appear perfectly, but no validation occurs (i.e. it allows redirect when no records are selected).  If I have the button set to the Javascript code it validates the records but doesn't display the selected records on the VF page.

I have searched the internet for hours on everything I could think of and couldn't find anything to help me.  

Can anyone out there offer a solution?

THANKS!!

Hi All,

 

We have a after insert trigger on EmailMessage object to Capture "To Email address" (routing address) in Email To Case(We have 10 routing address).

Whenever a Case gets created from Email to Case, in case history it shows like this.

 

        10/3/2012 11:28 AM       Surander           Changed Owner (Assignment) from  Gallucci to Team1.  

                                                                               Changed Owner (Assignment) from  Surander to Galluci.                          

                                                                               Created.

 

But Surander is the Automated Case User, Gallucci is the Default owner of a case when assignment rules fail to locate an owner and Team1 is Queue.

 

But ideally it should not Change the Owner to Gallucci (If assignment rules locates an Owner for Case). 

If i inactive the trigger it is working fine, and Case history shows like this. 

 

      10/3/2012 11:28 AM        Surander             Changed Owner (Assignment) from  Surander to Team1.                            

                                                                                Created.

 

I need to write a workflow, when ever case owner is Gallucci, but for each and every Case workflow is firing because of the above issue.

 

Trigger Code:

 

trigger ToAddress on EmailMessage (after insert) {    
    List<Case> cases = new List<Case>();
    for (Integer i = 0; i < Trigger.new.size(); i++ )
    {          
        try
        {
        EmailMessage newEmail = Trigger.new[i];
        List<Case> c = [SELECT id, Description, caseNumber FROM Case WHERE Id = :newEmail.ParentId];
        if (c.size() > 0 ){            
        c[0].To_Address__c= newEmail.ToAddress;           
             update c;            
         }  
       }
       catch(exception e)
        {
            System.debug('***********'+e);
        }  
       }   
          update cases;
}

 

 

Please reply with any coding or configuration that will help in this regard.

Any help is much appreciated.

 

Regards,

Susheel Reddy

show image of contact in formula field in contact detail page(image is stored in notes and attachments) whenever image is saved /changed/multiple image(only customisation - no coding) is stored(takes only first image)

I'm getting the followig error in my test method:

constructor not defined: [AccountOpenCasesExtension].<Constructor>()

 

I instantiated the class file and called my initialize method that is called within the constructor.  I'm not clear on why the constructor is not defined.  Shouldn't the constructor execute when the class is instantiated?

 

Here is my class file:

 

public class AccountOpenCasesExtension { private List<Account> accounts; public List<Account> getAccounts() { return accounts; } public AccountOpenCasesExtension(ApexPages.StandardController stdController) { init((Account)stdController.getRecord()); //accounts = [Select id, name, (Select Owner.Name, Contact.Name, CaseNumber, Subject, CreatedDate From Cases WHERE IsClosed = false) From Account a WHERE id =: stdController.getId()]; } public void init(Account a) { accounts = [Select id, name, (Select Owner.Name, Contact.Name, CaseNumber, Subject, CreatedDate From Cases WHERE IsClosed = false) From Account a WHERE id =: a.Id]; } static testMethod void test() { Account acct = [Select id, name, (Select Owner.Name, Contact.Name, CaseNumber, Subject, CreatedDate From Cases WHERE IsClosed = false) From Account a LIMIT 1]; AccountOpenCasesExtension ctrl = new AccountOpenCasesExtension(); ctrl.init(acct); } }