• Damien Phillippi033905702927186443
  • NEWBIE
  • 290 Points
  • Member since 2013

  • Chatter
    Feed
  • 10
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 65
    Replies
I understand that you can't insert more than 10,000 rows at once in a DML statement.  So, I wrote a little routine to do these 5,000 at a time (below).  Note that this is called in the 'finish' function of the batch process so it's gathered all of the relevant records, some 50,000 or so.

for (ID cID : contactIDs) {
      counter ++;
      STB_Constituent__c stbc = new STB_Constituent__c();
      stbc.Contact_ID__c = (String) cID;
      constituents.add(stbc);
      if (counter == 5000) {
       try {
         insert constituents;
          counter = 0;
          constituents.clear();
       } catch (System.DmlException dmlEx) {
         throw dmlEx;
       }

This code seems to be working well, but I'm still getting the error message.  Note that in my logs below it says it's only going to insert 5,000 records but then the next line says that's over 10,000.  Am I missing something as to what constitutes a "DML row".  I'll try again using a batch size of 1,000 and see how that goes.

11:27:54.704 (31704666000)|DML_BEGIN|[94]|Op:Insert|Type:STB_Constituent__c|Rows:5000
11:27:54.704 (31704687000)|EXCEPTION_THROWN|[94]|System.LimitException: Too many DML rows: 10001
11:27:54.704 (31704768000)|HEAP_ALLOCATE|[94]|Bytes:28
11:27:54.706 (31706178000)|FATAL_ERROR|System.LimitException: Too many DML rows: 10001
I have Leads related to Accounts (Account__c field on Leads).  I am trying to write a SOQL statement that pulls in all Leads and Contacts associated with specific Accounts.  Here is a general SOQL which I thought should work, but keeps giving me an error message.
acc = [select id,name,industry,billingcountry,createdbyid,(select id,name,email,phone from contacts), (select id, FirstName, LastName from leads) from account limit 20];
I keep getting this error no matter how I try to pull the Lead relationship:  COMPILE ERROR: Didn't understand relationship 'leads' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Any help would be greatly appreciated.
Thank you.
Hey All,

I believe my question will underline my lack of experience with Javascript more than anything else, but I am hoping this is the right place to ask this question anyway. I have a pageBlockTable that is iterating over a list of wrapper classes. Each wrapper class holds two select lists. The idea is to have one control the other. I uderstand how to use action functions to create a dependant picklist when all the requesite functionality resides in the controller itself. I seem to be missing something important when using action functions and specific individual iterations of a list. Can anyone help?

Short question - In the example page, controller and wrapper class below; how can I get the first select list for each iteration in the data table to control the second? The dependant select list outside the data table works as an example of what I am looking for.


<apex:page controller="TestController">

<apex:form id="pgFrm">
  <apex:actionFunction name="refreshDependent" action="{!buildSecondSelectList}" rerender="secList" />
  <apex:pageBlock title="Rerender Dependent Picklists" id="firstlBlk" >
   <apex:selectList value="{!val1}" size="1" onchange="refreshDependent()" id="firstList">
    <apex:selectOptions value="{!list1}"/>
   </apex:selectList>
   <apex:selectList value="{!val2}" size="1" id="secList">
    <apex:selectOptions value="{!list2}"/>
   </apex:selectList>
  </apex:pageBlock>
  <apex:pageBlock title="Test Wrapper Picklists" id="seclBlk" >
   <apex:pageBlockTable value="{!wrapperList}" var="wrapper" id="wrapperTable" >
    <apex:column headerValue="First Wrapper Select List" >
     <apex:selectList value="{!wrapper.wrapperVal1}" size="1" id="wrapFirList">
      <apex:selectOptions value="{!wrapper.wrapperList1}"/>
     </apex:selectList>
    </apex:column>
    <apex:column headerValue="Second Wrapper Select List" >
     <apex:selectList value="{!wrapper.wrapperVal2}" size="1" id="wrapSecList">
      <apex:selectOptions value="{!wrapper.wrapperList2}"/>
     </apex:selectList>
    </apex:column>
   </apex:pageBlockTable>
  </apex:pageBlock>
</apex:form>
</apex:page>


public with sharing class TestController {

public String val1 {get;set;}
public String val2 {get;set;}

public List<SelectOption> list1 {get;set;}
public List<SelectOption> list2 {get;set;}

public List<TestWrapper> wrapperList {get;set;}

public TestController() {
  wrapperList = new List<TestWrapper>();
  for (Integer i = 0; i < 3; i++) {
   wrapperList.add( new TestWrapper() );
  }
  buildFirstSelectList();
  buildSecondSelectList();
}

public void buildFirstSelectList() {
  list1 = new List<SelectOption>();
 
  list1.add( new SelectOption('Val1','Val1') );
  list1.add( new SelectOption('Val2','Val2') );
  list1.add( new SelectOption('Val3','Val3') );
}

public void buildSecondSelectList() {
  list2 = new List<SelectOption>();
  if (val1!=null&&val1=='Val1') {
   list2.add( new SelectOption('SecondVal1','SecondVal1') );
   list2.add( new SelectOption('SecondVal2','SecondVal2') );
   list2.add( new SelectOption('SecondVal3','SecondVal3') );
   list2.add( new SelectOption('SecondVal4','SecondVal4') );
  } else if (val1!=null&&val1=='Val2') {
   list2.add( new SelectOption('SecondVal5','SecondVal5') );
   list2.add( new SelectOption('SecondVal6','SecondVal6') );
   list2.add( new SelectOption('SecondVal7','SecondVal7') );
   list2.add( new SelectOption('SecondVal8','SecondVal8') );
  } else if (val1!=null&&val1=='Val3') {
   list2.add( new SelectOption('SecondVal9','SecondVal9') );
   list2.add( new SelectOption('SecondVal10','SecondVal10') );
   list2.add( new SelectOption('SecondVal11','SecondVal11') );
   list2.add( new SelectOption('SecondVal12','SecondVal12') );
  } else {
   list2.add( new SelectOption('SecondVal1','SecondVal1') );
   list2.add( new SelectOption('SecondVal2','SecondVal2') );
   list2.add( new SelectOption('SecondVal3','SecondVal3') );
   list2.add( new SelectOption('SecondVal4','SecondVal4') );
   list2.add( new SelectOption('SecondVal5','SecondVal5') );
   list2.add( new SelectOption('SecondVal6','SecondVal6') );
   list2.add( new SelectOption('SecondVal7','SecondVal7') );
   list2.add( new SelectOption('SecondVal8','SecondVal8') );
   list2.add( new SelectOption('SecondVal9','SecondVal9') );
   list2.add( new SelectOption('SecondVal10','SecondVal10') );
   list2.add( new SelectOption('SecondVal11','SecondVal11') );
   list2.add( new SelectOption('SecondVal12','SecondVal12') );
  }
}
}




public with sharing class TestWrapper {

public String wrapperVal1 {get;set;}
public String wrapperVal2 {get;set;}

public List<SelectOption> wrapperList1 {get;set;}
public List<SelectOption> wrapperList2 {get;set;}

public TestWrapper() {
  buildFirstSelectList();
  buildSecondSelectList();
}

public void buildFirstSelectList() {
  wrapperList1 = new List<SelectOption>();
 
  wrapperList1.add( new SelectOption('Wrapper Val1','Wrapper Val1') );
  wrapperList1.add( new SelectOption('Wrapper Val2','Wrapper Val2') );
  wrapperList1.add( new SelectOption('Wrapper Val3','Wrapper Val3') );
}

public void buildSecondSelectList() {
  wrapperList2 = new List<SelectOption>();
  if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val1') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal1','Wrapper SecondVal1') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal2','Wrapper SecondVal2') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal3','Wrapper SecondVal3') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal4','Wrapper SecondVal4') );
  } else if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val2') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal5','Wrapper SecondVal5') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal6','Wrapper SecondVal6') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal7','Wrapper SecondVal7') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal8','Wrapper SecondVal8') );
  } else if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val3') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal9','Wrapper SecondVal9') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal10','Wrapper SecondVal10') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal11','Wrapper SecondVal11') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal12','Wrapper SecondVal12') );
  } else {
   wrapperList2.add( new SelectOption('Wrapper SecondVal1','Wrapper SecondVal1') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal2','Wrapper SecondVal2') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal3','Wrapper SecondVal3') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal4','Wrapper SecondVal4') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal5','Wrapper SecondVal5') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal6','Wrapper SecondVal6') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal7','Wrapper SecondVal7') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal8','Wrapper SecondVal8') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal9','Wrapper SecondVal9') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal10','Wrapper SecondVal10') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal11','Wrapper SecondVal11') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal12','Wrapper SecondVal12') );
  }
}
}
Hi,

Just a general question, how do you plan a project in salesforce if you quite new to the language.  What do people generally do, do they keep it in house or go to a third party company.

Do you spend a week planning, looking at what is risky etc.

Regards

Richard
I have a VF page displaying as a component in a custom console. It allows the user to perform what I call "quick edits" for a few key fields. When the console is opened, those fields are displayed with the component in edit mode. If the users changes or adds to these fields, then clicks save, it does save the records as I want it to. However, instead of refreshing to display the VF page, it refreshes to display the page layout of the (custom) object into which the records were saved. 

For a visual example, the first screen shot is what I want the left side component to look like all the time (before a save and after a save).
console component (VF page) as I want it to be before and after a save


This is what the page looks like after a save - it displays the object's detail page in view mode. I want it to display my custom VF page which is the edit mode shown above. 

User-added image


Is this possible? Thanks in advance for any contributions!
The following query returns the error below and I'm not sure why.  If I remove the "AND (p.AccountToId != Opportunity.AccountId)" then it returns 2 rows.

SELECT p.OpportunityId, p.AccountToId, p.Role, p.IsPrimary, Opportunity.AccountId
FROM Partner p
WHERE (p.OpportunityId = 'XXXXXXX') AND (p.AccountToId != Opportunity.AccountId)

In the actual query 'XXXXXXX' is a valid ID

MALFORMED_QUERY
unexpected token: 'Opportunity.AccountId'

Any idea what I'm doing wrong?
When I run a simple query which gets data from a parent table that data is not displayed.  It just displays the name of the parent table.  See screenshot:
User-added image

It doesn't seem to matter what field I choose or what parent table I connect to.  

When I run this same query through the Developer console it displays as expected.  I'm using Eclipse 4.3 (Kepler) with a fresh install of the Force.com IDE plugin.  I looked through the known issues and I didn't see anything that pertains to this.  Any idea what's going on here?
Here is the scenario:
• 50,000+ Accounts exist in the system
• The Account fields need to be copied over to a custom object(that is linked to its respective Account)
• A trigger can be used to insert, delete, and update records through the Sf user interface
 
I need to figure out a way to create 50, 000+ custom object records through a schedulable batch Apex class. Any ideas other than using Data Loader?
  • January 13, 2014
  • Like
  • 0
Hi,
I have a trigger  to delete cases created from bounce mails or undeliverable email (email- to-case). The triiger is not working and i am getting  the below error

The following errors were encountered while processing an incoming email:

INVALID_CROSS_REFERENCE_KEY : invalid cross reference id INVALID_CROSS_REFERENCE_KEY : invalid cross reference id

My triiger code----------------------------


trigger deleteOutOfOfficeEmailAndCases on EmailMessage (after insert) {
   
    if(trigger.isinsert && trigger.isAfter)
    {
         Set<Id> deleteEmailIds = new Set<Id>();
         set<Id> deleteCaseIds = new Set<Id>();
         List<EmailMessage> emailMsgdeleteList = new List<EmailMessage>();
         List<case> deleteCasesList = new List<Case>();
         Set<Id> applicableCaseRecTypes = new Set<Id>();        
         List<Attachment> emailAttachmentDeleteList = new List<Attachment>();
       
        
         for(EmailMessage em : trigger.new)
         {
              if(em.Incoming == true && em.ReplyToEmailMessageId == null)
                {
                    //Bounced Email delete
                    if(em.FromAddress != null)
                    {
                        // the email statarts with 'mailer-daemon' or postmaster are the bounce email address
      if(em.FromAddress.containsIgnoreCase('mailer-daemon') ||em.FromAddress.containsIgnoreCase('postmaster'))
                            deleteEmailIds.add(em.id);
                    }
                   
                }
         }        
         if(!deleteEmailIds.isEmpty())
         {
             for(Attachment atmt :[select Id,ParentId from Attachment where parentId in :deleteEmailIds])
             {
                 emailAttachmentDeleteList.add(atmt);
             }
             for(EmailMessage email : [select id, parentId from EmailMessage where id in :deleteEmailIds])
             {
                 emailMsgdeleteList.add(email);
                 deleteCaseIds.add(email.parentId);
             }
             if(!deleteCaseIds.isEmpty())
             {
                 for(Case c : [select id,casenumber, subject from case where id in :deleteCaseIds])
                 {
                    deleteCasesList.add(c);
                 }
             }        
             if(!emailMsgdeleteList.isEmpty())
             {
                 if(!emailAttachmentDeleteList.isEmpty())
                        delete emailAttachmentDeleteList;
                 delete emailMsgdeleteList;
                
                 if(!deleteCasesList.isEmpty())
                     delete deleteCasesList;
             }
         }        
   }                      

}

Can any body plz let me know how to do this.

Thanks

  • January 13, 2014
  • Like
  • 0
In this trigger, I am looking up the strategic industry based on the market segment in the Industry Definition table. My problem is I cannot commit the resulting industry value to the original record. I have tried to achieve my objective through the admin tools and cannot. How do I save the resulting strategic industry value to customer_product_line_item___c record?

Thank you very much.

trigger IndustrytoAcctOpp on Customer_Product_Line_Item__c (Before Insert, Before Update) {

    Set<Id> iid = new Set<Id>();
    Set<Id> aid = new Set<Id>();
    Set<Id> oid = new Set<Id>();
    String Industry;
    String Marketsegment;
    string StrategicIndustry;
   
    For(Customer_Product_Line_Item__c cpli : trigger.new){
        iid.add(cpli.id);
        aid.add(cpli.Account__c);
        oid.add(cpli.Opportunity__c);
        MarketSegment = cpli.industry_segment__c;
        system.debug('##########marketsegment:'+ marketsegment);
    }

    List<Industry_Definition__c> idlist = new List<Industry_Definition__c> ([select id, Market_segment__c, Strategic_Industry__c from Industry_Definition__c]);
   
    Map<string, Industry_Definition__c> imap = new Map<string, Industry_Definition__c>();
   
    for(Industry_Definition__c i : [select id, Market_Segment__c, Strategic_Industry__c from Industry_Definition__c]){
        imap.put(i.Market_Segment__c, i);
        system.debug('##########i.Market_segment__c:'+ i.market_segment__c);
    }
                     

    For(Customer_Product_Line_Item__c cpl : [select id, Bulk_Density__c, Industry_Segment__c, Strategic_Industry__c from Customer_Product_Line_Item__c where id=:iid]){
        system.debug('##########imap.get(cpl.industry_Segment__c):'+ cpl.industry_Segment__c);
        system.debug('##########imap.get(cpl.industry_Segment__c).Strategic_Industry__c:'+imap.get(cpl.industry_Segment__c).Strategic_Industry__c);
        cpl.Strategic_Industry__c = imap.get(cpl.industry_Segment__c).Strategic_Industry__c;

    }

}
I'm not sure if this is the right place to ask.... but there doesn't really seem to be a clear avenue.

I left my old job a couple of months ago, but apparently my person devbox login was somehow attached to that email (even though my person email address was the login).  Now when I go to try to log into my box it doens't let me since it doesn't recognize the computer I currently use, and it sends an email to my old work email to validate my computer.  How can I contact Salesforce to try and get this fixed?
I am trying to access a Map<String,Map<String,Integer> in VF but I dont want to use repeat tag, as I know we can access a Map<String,String> as {!MapVal['Key']} in a page without any error.

but for the Map<String,Map<String,Integer> when I do this {!MapVal['Key']} it through a error as value not found in map. But at lest I should get the inside Map!!

Any Help!!
  • January 30, 2014
  • Like
  • 0
I'm not sure if this is the right place to ask.... but there doesn't really seem to be a clear avenue.

I left my old job a couple of months ago, but apparently my person devbox login was somehow attached to that email (even though my person email address was the login).  Now when I go to try to log into my box it doens't let me since it doesn't recognize the computer I currently use, and it sends an email to my old work email to validate my computer.  How can I contact Salesforce to try and get this fixed?
trigger to update lookup fields in 2 object lookup fields My requirement is :
ex:- accounts and contacts objects has common field city if i update city field in accounts then it must update in contacts also.


 i am having 2 lookup fields in 2 different objects which is a common field named  "city"

If i update a city name using lookup for example california is changed to *washington* the change must update all records which have california must be changed to washington the changes must reflect in 2 objects same time.


Hi everyone.

Can you please help me to fix this error: I have a trigger that would send an email alert to new AssignedTo user. But it through an error if the Site Defect is a new record. in other word when the Trigger.old[0].Assigned_To__c is empty. 

here is the code:

trigger SendEmailAlertToAssignedTo on Site_Defects__c (after insert, before update) { // I have the error message here

    if(Trigger.new[0].Assigned_To__c != Trigger.old[0].Assigned_To__c ) {
       
            //Sending Mail
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
          
                //Setting user email in to address
            String userName = Trigger.new[0].Assigned_To__c;
             
            User AT = [Select Email From User where id= : userName ]; 
            String userEmail = AT.Email;
          
          
            //String email = Trigger.new[0].RegionalManager__c;
            String[] toAddresses = new String[] {userEmail} ;
          
            // Assign the addresses for the To and CC lists to the mail object
            mail.setToAddresses(toAddresses );
            mail.setToAddresses(MyEmail);
          
            //Email subject to be changed
            mail.setSubject('THIS IS A TEST. Site Defect Owner Changed');
            String body = AT.Email+'The owner of Site Defect ' + trigger.Old[0].Name +' has been changed <br> <br>'+
            'Regards <br> ';
            //Body of email
            mail.setHtmlBody(body);
          
            //Sending the email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
}

Thank you. 

What is the work around? We have not hit this limit as of yet.....but I have the feeling that we will.  With all of the 3rd party apps, Javascript, CSS and all that good stuff....Now we have to add Forms to this, there are over 1,000 Forms! 

Has anyone ran into this issue? 

How did you solve it?

  • January 27, 2014
  • Like
  • 0
I understand that you can't insert more than 10,000 rows at once in a DML statement.  So, I wrote a little routine to do these 5,000 at a time (below).  Note that this is called in the 'finish' function of the batch process so it's gathered all of the relevant records, some 50,000 or so.

for (ID cID : contactIDs) {
      counter ++;
      STB_Constituent__c stbc = new STB_Constituent__c();
      stbc.Contact_ID__c = (String) cID;
      constituents.add(stbc);
      if (counter == 5000) {
       try {
         insert constituents;
          counter = 0;
          constituents.clear();
       } catch (System.DmlException dmlEx) {
         throw dmlEx;
       }

This code seems to be working well, but I'm still getting the error message.  Note that in my logs below it says it's only going to insert 5,000 records but then the next line says that's over 10,000.  Am I missing something as to what constitutes a "DML row".  I'll try again using a batch size of 1,000 and see how that goes.

11:27:54.704 (31704666000)|DML_BEGIN|[94]|Op:Insert|Type:STB_Constituent__c|Rows:5000
11:27:54.704 (31704687000)|EXCEPTION_THROWN|[94]|System.LimitException: Too many DML rows: 10001
11:27:54.704 (31704768000)|HEAP_ALLOCATE|[94]|Bytes:28
11:27:54.706 (31706178000)|FATAL_ERROR|System.LimitException: Too many DML rows: 10001
I have Leads related to Accounts (Account__c field on Leads).  I am trying to write a SOQL statement that pulls in all Leads and Contacts associated with specific Accounts.  Here is a general SOQL which I thought should work, but keeps giving me an error message.
acc = [select id,name,industry,billingcountry,createdbyid,(select id,name,email,phone from contacts), (select id, FirstName, LastName from leads) from account limit 20];
I keep getting this error no matter how I try to pull the Lead relationship:  COMPILE ERROR: Didn't understand relationship 'leads' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Any help would be greatly appreciated.
Thank you.
I have a dataTable and one of the column is a checkbox. Onchange of the checkbox, an update is made to the database. 

If the checkbox is made true on say row1, how can I remove that row1 from the vsiaulforce page display. I am not removing it from the database, just not wanting to show in the VFP.

<br/></br>

I don't want to render, becuase that leaves an empty row.

This is my code. 

<pre>

public class dataTableCon {

    public Id accountId { get; set; }
    
    ID aid = apexPages.currentPage().getParameters().get('aid');
    public List<Account> accounts ;
   
    public dataTableCon (){
     
   
    }
   

    public List<Account> getAccounts() {

        if(accounts == null) accounts = [select name, owner.name,hidden_field__c from account limit 10];

        return accounts;

    }

   

    public void saveAccount(){

    system.debug('&****************');
     Map<Id,Account> map_Accounts = new Map<Id,Account>(accounts);

        update map_Accounts.get(accountid);

    }
}

</pre>

VFP

<pre>

<apex:page controller="dataTableCon" id="page">
   
<apex:form >
<apex:pageBlock id="theBlock">
   
    <apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even" styleClass="tableClass">
   
        <apex:column >
            <apex:facet name="header">Private</apex:facet>
             <apex:inputCheckbox value="{!account.hidden_field__c}" >
             <apex:actionSupport event="onchange" action="{!saveAccount}" reRender="theBlock">
                <apex:param name="accountId" value="{!account.Id}" assignTo="{!accountId}"/>
             </apex:actionSupport>            

           </apex:inputCheckbox>           
        </apex:column>
   
       
        <apex:column >
            <apex:facet name="header">Name</apex:facet>
            <apex:outputText value="{!account.name}" / >
        </apex:column>
   
        <apex:column >
            <apex:facet name="header">Owner</apex:facet>
            <apex:outputText value="{!account.owner.name}"  />
        </apex:column>
       
    </apex:dataTable> 
   
    </apex:pageBlock>
    </apex:form>
</apex:page>

</pre>
Hey All,

I believe my question will underline my lack of experience with Javascript more than anything else, but I am hoping this is the right place to ask this question anyway. I have a pageBlockTable that is iterating over a list of wrapper classes. Each wrapper class holds two select lists. The idea is to have one control the other. I uderstand how to use action functions to create a dependant picklist when all the requesite functionality resides in the controller itself. I seem to be missing something important when using action functions and specific individual iterations of a list. Can anyone help?

Short question - In the example page, controller and wrapper class below; how can I get the first select list for each iteration in the data table to control the second? The dependant select list outside the data table works as an example of what I am looking for.


<apex:page controller="TestController">

<apex:form id="pgFrm">
  <apex:actionFunction name="refreshDependent" action="{!buildSecondSelectList}" rerender="secList" />
  <apex:pageBlock title="Rerender Dependent Picklists" id="firstlBlk" >
   <apex:selectList value="{!val1}" size="1" onchange="refreshDependent()" id="firstList">
    <apex:selectOptions value="{!list1}"/>
   </apex:selectList>
   <apex:selectList value="{!val2}" size="1" id="secList">
    <apex:selectOptions value="{!list2}"/>
   </apex:selectList>
  </apex:pageBlock>
  <apex:pageBlock title="Test Wrapper Picklists" id="seclBlk" >
   <apex:pageBlockTable value="{!wrapperList}" var="wrapper" id="wrapperTable" >
    <apex:column headerValue="First Wrapper Select List" >
     <apex:selectList value="{!wrapper.wrapperVal1}" size="1" id="wrapFirList">
      <apex:selectOptions value="{!wrapper.wrapperList1}"/>
     </apex:selectList>
    </apex:column>
    <apex:column headerValue="Second Wrapper Select List" >
     <apex:selectList value="{!wrapper.wrapperVal2}" size="1" id="wrapSecList">
      <apex:selectOptions value="{!wrapper.wrapperList2}"/>
     </apex:selectList>
    </apex:column>
   </apex:pageBlockTable>
  </apex:pageBlock>
</apex:form>
</apex:page>


public with sharing class TestController {

public String val1 {get;set;}
public String val2 {get;set;}

public List<SelectOption> list1 {get;set;}
public List<SelectOption> list2 {get;set;}

public List<TestWrapper> wrapperList {get;set;}

public TestController() {
  wrapperList = new List<TestWrapper>();
  for (Integer i = 0; i < 3; i++) {
   wrapperList.add( new TestWrapper() );
  }
  buildFirstSelectList();
  buildSecondSelectList();
}

public void buildFirstSelectList() {
  list1 = new List<SelectOption>();
 
  list1.add( new SelectOption('Val1','Val1') );
  list1.add( new SelectOption('Val2','Val2') );
  list1.add( new SelectOption('Val3','Val3') );
}

public void buildSecondSelectList() {
  list2 = new List<SelectOption>();
  if (val1!=null&&val1=='Val1') {
   list2.add( new SelectOption('SecondVal1','SecondVal1') );
   list2.add( new SelectOption('SecondVal2','SecondVal2') );
   list2.add( new SelectOption('SecondVal3','SecondVal3') );
   list2.add( new SelectOption('SecondVal4','SecondVal4') );
  } else if (val1!=null&&val1=='Val2') {
   list2.add( new SelectOption('SecondVal5','SecondVal5') );
   list2.add( new SelectOption('SecondVal6','SecondVal6') );
   list2.add( new SelectOption('SecondVal7','SecondVal7') );
   list2.add( new SelectOption('SecondVal8','SecondVal8') );
  } else if (val1!=null&&val1=='Val3') {
   list2.add( new SelectOption('SecondVal9','SecondVal9') );
   list2.add( new SelectOption('SecondVal10','SecondVal10') );
   list2.add( new SelectOption('SecondVal11','SecondVal11') );
   list2.add( new SelectOption('SecondVal12','SecondVal12') );
  } else {
   list2.add( new SelectOption('SecondVal1','SecondVal1') );
   list2.add( new SelectOption('SecondVal2','SecondVal2') );
   list2.add( new SelectOption('SecondVal3','SecondVal3') );
   list2.add( new SelectOption('SecondVal4','SecondVal4') );
   list2.add( new SelectOption('SecondVal5','SecondVal5') );
   list2.add( new SelectOption('SecondVal6','SecondVal6') );
   list2.add( new SelectOption('SecondVal7','SecondVal7') );
   list2.add( new SelectOption('SecondVal8','SecondVal8') );
   list2.add( new SelectOption('SecondVal9','SecondVal9') );
   list2.add( new SelectOption('SecondVal10','SecondVal10') );
   list2.add( new SelectOption('SecondVal11','SecondVal11') );
   list2.add( new SelectOption('SecondVal12','SecondVal12') );
  }
}
}




public with sharing class TestWrapper {

public String wrapperVal1 {get;set;}
public String wrapperVal2 {get;set;}

public List<SelectOption> wrapperList1 {get;set;}
public List<SelectOption> wrapperList2 {get;set;}

public TestWrapper() {
  buildFirstSelectList();
  buildSecondSelectList();
}

public void buildFirstSelectList() {
  wrapperList1 = new List<SelectOption>();
 
  wrapperList1.add( new SelectOption('Wrapper Val1','Wrapper Val1') );
  wrapperList1.add( new SelectOption('Wrapper Val2','Wrapper Val2') );
  wrapperList1.add( new SelectOption('Wrapper Val3','Wrapper Val3') );
}

public void buildSecondSelectList() {
  wrapperList2 = new List<SelectOption>();
  if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val1') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal1','Wrapper SecondVal1') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal2','Wrapper SecondVal2') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal3','Wrapper SecondVal3') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal4','Wrapper SecondVal4') );
  } else if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val2') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal5','Wrapper SecondVal5') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal6','Wrapper SecondVal6') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal7','Wrapper SecondVal7') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal8','Wrapper SecondVal8') );
  } else if (wrapperVal1!=null&&wrapperVal1=='Wrapper Val3') {
   wrapperList2.add( new SelectOption('Wrapper SecondVal9','Wrapper SecondVal9') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal10','Wrapper SecondVal10') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal11','Wrapper SecondVal11') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal12','Wrapper SecondVal12') );
  } else {
   wrapperList2.add( new SelectOption('Wrapper SecondVal1','Wrapper SecondVal1') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal2','Wrapper SecondVal2') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal3','Wrapper SecondVal3') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal4','Wrapper SecondVal4') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal5','Wrapper SecondVal5') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal6','Wrapper SecondVal6') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal7','Wrapper SecondVal7') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal8','Wrapper SecondVal8') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal9','Wrapper SecondVal9') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal10','Wrapper SecondVal10') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal11','Wrapper SecondVal11') );
   wrapperList2.add( new SelectOption('Wrapper SecondVal12','Wrapper SecondVal12') );
  }
}
}
I want to write test class for this Email Service apex class

global class ResourceToLeave implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
                                                       Messaging.InboundEnvelope env){

    // Create an InboundEmailResult object for returning the result of the
    // Apex Email Service
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
   
    String[] emailBody = email.plainTextBody.split('\n', 0);
   
    String startdate = emailBody[0].substring(10);
    String[] tempStr = startdate.split('/');
    Integer d = Integer.valueOf(tempStr[0]);
    Integer m = Integer.valueOf(tempStr[1]);
    Integer y = Integer.valueOf(tempStr[2]);
    Date sdt = Date.newInstance(y,m,d);
   
    String enddate = emailBody[1].substring(8);
    String[] tempStr1 = enddate.split('/');
    Integer dd = Integer.valueOf(tempStr1[0]);
    Integer mm = Integer.valueOf(tempStr1[1]);
    Integer yy = Integer.valueOf(tempStr1[2]);
    Date edt = Date.newInstance(yy,mm,dd);
      
    // New Leave object to be created
    Leave__c[] leave = new Leave__c[0];
  
    // Try to look up any contacts based on the email from address
    // If there is more than one contact with the same email address,
    // an exception will be thrown and the catch statement will be called.
    try {
      Resource__c[] resource = [SELECT Id, Name FROM Resource__c WHERE Name = :email.subject LIMIT 1];
     
      Resource__c res;
      if(resource.size()>0)
      {
          res=resource[0];
      }
      // Add a new Task to the contact record we just found above.
      leave.add(new Leave__c(Resource__c=res.Id,
                             Start_Date__c=sdt,
                             End_Date__c=edt
                             ));
    
     // Insert the new Leave
     insert leave;   
    
     System.debug('New Leave Object: ' + leave );  
    }
    // If an exception occurs when the query accesses
    // the contact record, a QueryException is called.
    // The exception is written to the Apex debug log.
   catch (System.QueryException e) {
       System.debug('Query Issue: ' + e);
   }
  
   // Set the result to true. No need to send an email back to the user
   // with an error message
   result.success = true;
  
   // Return the result for the Apex Email Service
   return result;
  }
}
  • January 08, 2014
  • Like
  • 0