• Baguiar
  • NEWBIE
  • 150 Points
  • Member since 2009

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 41
    Questions
  • 104
    Replies

Hi All,

 

I have a requirement where I need to update some fields of opportunity. I have another custom object  with many fields( apprx 10000 records). Now I need to update fields of oportunity with the filds of custom object. Records are already present in both the object. What would be the best solution for this.

 

Thanks in advance!

 

Regards

Alok 

How do I a write trigger on a checkbox. I am trying to change the value of a picklist based on a checkbox click. Do i even need to write an apex trigger for this, or is there any other method of achieving this? I dont want to write a trigger to update the record, but just need to change the value of the picklist before even the user hits save button.

 

Thanks

 

HI there,

 

I have a formula field that reads:

 

CASE(Ownerid,005A0000000123,
"John Smith"& BR()
&"Senior Services Associate"& BR()
&"p:718.111.22222"& BR()
&"e: jsmith@tester.com ",005A0000000456,
"Mary Smith"& BR() 
&"Director of Services"& BR() 
&"p: 718.111.3333"& BR() 
&"e: mary@tester.com", "No owner")

 this works for the email signature, according to the owner of the Lead. The formula displays the values just fine with the paragraphs correctly within salesforce pages. Now, when I use the field in an email template, the result is a lot os <BR> where there was supposed to be just another paragraph.

like:

 

John Smith <BR> Senior Services Associate <br> p: 718.111.2222 <br> e: jophn@tester.com

 

Again, looking at the field in Salesforce, it displays just fine with the page breaks.

 

Thanks!!

B

I've searched a bit and found some posts about using the IF statement within a VF page, but wasn;t clear about the possibility of using it for a simple display of a html page.

 

The controller is the standard ACCOUNT object.

All I need is something like this:

 

<apex:page standardController="account">
{!IF(isnull(account.JOB__c),"No Job","

<html>

some HTML coding here....

</html>"
)
}
</apex:page>

 The syntax is probably wrong, but I was wondering if this is possible.

 

Thanks in advance!

B

IS there a way to export the recycle bin to CSV or something like that ? 

I need to look at the details of some deleted records but I do not want to restore the record to the database.

 

Thanks for the help!

Breno

Hello!

 

I want to change a value on a SelectList item in a VF page I have named "Task_Type". The selectList is:

 

<apex:selectList id="rangedate" value="{!rangedate}" size="1" >
<apex:selectoption itemLabel="30" itemValue="30"></apex:selectoption>
<apex:selectoption itemLabel="60" itemValue="60"></apex:selectoption>
<apex:selectoption itemLabel="90" itemValue="90"></apex:selectoption>
<apex:selectoption itemLabel="180" itemValue="180"></apex:selectoption>
</apex:selectList>

I want to pick another value of that list so that i can increase the coverage on my test Method. I can call the page through:

 

    PageReference pageRef = Page.Task_type;      


but I'm having a hard time with the syntax in how to set the value of "rangedate" to "30" for example. Thanks for the HELP!

  • September 14, 2011
  • Like
  • 0

Hi there,

 

I have this VF page that runs a report based on the select list criteria. I had the class and test class working fine, until I had to add the option "All" onm the selectlist and , therefore, modify the controller for the new value. Got the controller to work but on my test class, I'm having a problem in testing exactly the ELSE statements. I think because that requires me to test the class also with other values from the selectlist.

 

Any help is appreciated! Here goes the Class, page and test class: (I've made the lines not covered on the class underlined and italic.)

 

public class TaskLeaderNO
{ 
    public PageReference Refreshtsk() {
        return page.Task_LeadershipNO;
    }
    
     public PageReference toexcel() {
        return page.Task_LeadershipXLSNO;
    }
     
  public String positions {get; set;}
  public String rangedate {get; set;}
  public String tasktype {get; set;}
  
  Date candDate;
  Date candDate1;

  public TaskLeaderNO()
  {
     rangedate='30';
     candDate=System.today(); 
     tasktype='All';  
     positions='All';   
  }

   Set<Id> tskNo = new Set<Id>();
 
  private List<Contact> ContactNO;
  public List<Contact> getContactNO()
   {
   candDate1=System.today()-Integer.valueOf(rangedate);
   tskNo = new set<ID>();
   
   IF (tasktype == 'All') {
   for (Task t: [Select WhoID FROM task WHERE OwnerID = :UserInfo.getUserId() and activitydate >= :candDate1])
   tskNo.add(t.WhoID);   
     } else {
 for (Task t: [Select WhoID FROM task WHERE OwnerID = :UserInfo.getUserId() and activitydate >= :candDate1 and type= :tasktype]) tskNo.add(t.WhoID); }   
   
    IF (positions == 'All') {
  
   Contact[] ContactNO = [Select id, AccountId, Account.name, Email, Name, account.billingcity, account.billingstate from Contact 

WHERE ID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE (Position__c = 'President' OR Position__c = 'Education Director' OR 

Position__c ='Co-President' OR Position__c = 'Senior (or only) Rabbi' OR Position__c = 'Administrator/Exec director') and  (Thru_Date__c = 

null OR 

Thru_Date__c > :system.today()) and (Start_Date__C <= :system.today()) ) and account.Congregational_Rep__c = :UserInfo.getUserId() 

and ID NOT IN :tskNO];
   return ContactNO;
    } else {

 Contact[] ContactNO = [Select id, AccountId, Account.name, Email, Name, account.billingcity, account.billingstate from Contact WHERE ID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE Position__c = :positions and (Thru_Date__c = null OR Thru_Date__c > :system.today()) and (Start_Date__C <= :system.today()) ) and account.Congregational_Rep__c = :UserInfo.getUserId() and ID NOT IN :tskNO]; return ContactNO;

     }
   }

}

 

Page:

<apex:page controller="TaskLeaderNO" showHeader="false" >
<apex:form >
<apex:pageBlock id="pageBlock" Title="NO Activities with Key Leadership">
<apex:pageMessages ></apex:pageMessages>
<b>Select Position:   </b>
<apex:selectList id="Positions" value="{!positions}" size="1">
<apex:selectoption itemLabel="All" itemValue="All"></apex:selectoption>
<apex:selectoption itemLabel="President" itemValue="President"></apex:selectoption>
<apex:selectoption itemLabel="Co-President" itemValue="Co-President"></apex:selectoption>
<apex:selectoption itemLabel="Senior (or only) Rabbi" itemValue="Senior (or only) Rabbi"></apex:selectoption>
<apex:selectoption itemLabel="Administrator/Exec Director" itemValue="Administrator/Exec Director"></apex:selectoption>
<apex:selectoption itemLabel="Education director" itemValue="Education director"></apex:selectoption>
</apex:selectList>
<b> How many days back? </b>
<apex:selectList id="rangedate" value="{!rangedate}" size="1" >
<apex:selectoption itemLabel="30" itemValue="30"></apex:selectoption>
<apex:selectoption itemLabel="60" itemValue="60"></apex:selectoption>
<apex:selectoption itemLabel="90" itemValue="90"></apex:selectoption>
<apex:selectoption itemLabel="180" itemValue="180"></apex:selectoption>
</apex:selectList>
<b>   </b>
<b> Activity Type </b>
<apex:selectList id="tasktype" value="{!tasktype}" size="1" >
<apex:selectoption itemLabel="All" itemValue="All"></apex:selectoption>
<apex:selectoption itemLabel="Phone Call" itemValue="Phone Call"></apex:selectoption>
<apex:selectoption itemLabel="Email" itemValue="Email"></apex:selectoption>
</apex:selectList>
<b>   </b>
<apex:commandButton action="{!Refreshtsk}" value="Run Report" />
<b>   </b>
<apex:commandButton action="{!toexcel}" value="Export to Excel" />
<apex:pageBlockTable value="{!ContactNO}" var="cont" rendered="{!NOT(ISNULL(ContactNO))}" id="tblContactNo">
<apex:column headerValue="Name" ><apex:outputLink value="/{!cont.id}" target="_parent">{!cont.Name}
</apex:outputLink></apex:column>
<apex:column value="{!cont.Email}"></apex:column>
<apex:column headerValue="Congregation" value="{!cont.account.name}"></apex:column>
<apex:column value="{!cont.account.billingcity}"></apex:column>
<apex:column value="{!cont.account.billingstate}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>

</apex:page>

 And test:

 

@isTest
private  class TestTaskleaderNO
{
   static testMethod void testgetContactNO()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     
      // insert a test contact
      List<Contact> con=new List<Contact>{new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com', Key_Contact__C = True), 
            new Contact(FirstName='Lester2', Lastname='DbigTester2', accountID=acc.id, email='2222222@22225.com', Key_Contact__C = True)};
      insert con;

      // insert some test leadership codes
      List<leadership_position_code__c> LDS=new List<leadership_position_code__c>{new leadership_position_code__c(Contact__C=con[0].id, position_type__C='Officer', Position__C='President', Start_Date__C= system.Today()-1 )};
      insert LDS;

    List<task> tasks = new List<task>{ new task(WhoId=con[0].Id,Subject='HEllo Task',ActivityDate=System.today()-10, activity_type__C = 'Email', Priority = 'Normal', Status = 'In Progress' ),
                                        new task(WhoId=con[1].Id,Subject='HEllo Task2',ActivityDate=System.today()-12, activity_type__C = 'Email', Priority = 'Normal', Status = 'In Progress' )   };
    insert tasks;


      // captures the acc id for the page     
      


      // instantiate the class under test
      TaskLeaderNO tl=new TaskLeaderNO();
     
      List<Contact> ContOK=tl.getContactNO();
      tl.refreshtsk();
      tl.toexcel();

      // change the number below to the number of leadership_position_code__c objects created above
      System.assertEquals(0, ContOK.size());
      
            
   }

 Thanks again!

 

B

 

  • September 09, 2011
  • Like
  • 0

Hi there,

 

still strugling with the test method for this wrapperclass as I can't pass 30% coverage. HAd some good help but still fighting it! :)

 

Here is the class:

 

public class wrapperClassController {
        
    GW_Volunteers__Volunteer_Shift__c[] stravail = [Select id, GW_Volunteers__Volunteer_Job__c, Shift_weekday__c from GW_Volunteers__Volunteer_Shift__c where id = :System.currentPagereference().getParameters().get('id')];
     
    public List<cContact> contactList {get; set;}

    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [Select c.ID, c.GW_Volunteers__Volunteer_Availability__c, c.GW_Volunteers__Volunteer_Status__c, c.Name, c.Volunteers_OK__c FROM Contact c WHERE c.Volunteers_OK__c = True and (c.GW_Volunteers__Volunteer_Availability__c INCLUDES (:stravail[0].Shift_weekday__c)) ]) {
                // As each contact is processed we create a new cContact object and add it to the contactList
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }

    public PageReference processSelected() {

                
        List<Contact> selectedContacts = new List<Contact>();

        for(cContact cCon : getContacts()) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
            }
        }

        System.debug('These are the selected Contacts...');
        for(Contact con : selectedContacts) {
            GW_Volunteers__Volunteer_Hours__c newvolu = new GW_Volunteers__Volunteer_Hours__c( GW_Volunteers__Contact__c = Con.id, GW_Volunteers__Volunteer_Job__c = stravail[0].GW_Volunteers__Volunteer_Job__c, GW_Volunteers__Volunteer_Shift__c = stravail[0].id, GW_Volunteers__Start_Date__c = system.today(), GW_Volunteers__Status__c = 'Scheduled', GW_Volunteers__Number_of_Volunteers__c = 1 );
            insert newvolu;
        
            system.debug(con);
        }
        return null;
    }

    public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}

        
        public cContact(Contact c) {
            con = c;
            selected = false;
        }
    }
}

 And the test Method:

 

@isTest
private  class TestwrapperClassController
{
   static testMethod void testgetContacts()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     
      // insert a test contact
      List<Contact> con=new List<Contact>{new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Wednesday morning' ), 
            new Contact(FirstName='Lester2', Lastname='DbigTester2', accountID=acc.id, email='1231@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Friday morning')};
      insert con;
      
     Campaign  CP = new Campaign ( name='TESTCPG' );
     insert CP ;

    GW_Volunteers__Volunteer_Job__c  GMVjob = new GW_Volunteers__Volunteer_job__c ( Name='Testjob', GW_Volunteers__Campaign__c=CP.id );
    insert GMVjob ;

    GW_Volunteers__Volunteer_Shift__c  GMVShift = new GW_Volunteers__Volunteer_Shift__c ( GW_Volunteers__Volunteer_Job__c=GMVjob.id , GW_Volunteers__Start_Date_Time__c =System.now(), GW_Volunteers__Duration__c = 3);
    insert GMVShift ;
      
    PageReference pageRef = Page.Match_Availability;       
    pageRef.getParameters().put('id' , GMVShift.id);
    Test.setCurrentPageReference(pageRef);

       
      wrapperClassController stdCon=new wrapperClassController();
      system.debug('******TEST-stdCon='+ stdCon); 
           
      stdCon.contactList = stdCon.getcontacts();
      for (Integer i = 0; i < 3; i++) {
        system.debug('******TEST-getContacts[' + i + '].con=' + stdCon.ContactList[i].con);
    }
    System.assertEquals(true,stdCon.ContactList[1].con.Volunteers_OK__c);
    
      stdCon.ContactList[1].selected=True;  
           system.debug('******TEST-OPPORTUNITY 1 SELECT stdCon.ContactList[1].selected=' + 
        stdCon.ContactList[1].selected); 
        
         stdCon.processSelected();  
         
    
   }
}

 HELP! :)

Hi there,

 

Posted before here an issue I'm having with a test method and, after looking at it I've noticed the List index out of bounds: 0. Thats because of a criteria on my SOQL statement that reads : 

 

(c.GW_Volunteers__Volunteer_Availability__c INCLUDES (:stravail[0].Shift_weekday__c)) 

 

Well, the Shift_weekday__c is on another SOQL that pulls the record ID from the current page that the user is in. The controller (wrapperclasscontroller) was built so that the user hits a button from a page and it pulls a report based on the Shift_weekday__c from the current record on the page the user is hitting the button from. The report comes up and gives the user check boxes so that you can chose the records and hit a button that will create records on a diferent object (Not the CONTACT) using the current contact IDs.

 

MY issue is How do I call the page and set some test Shift_weekday__c from the test method, just so that when I call the getcontacts() , my List does not return 0 (zero) records. The test method is really where I'm stuck.

 

Here is the controller:

 

public class wrapperClassController {
        
    GW_Volunteers__Volunteer_Shift__c[] stravail = [Select id, GW_Volunteers__Volunteer_Job__c, Shift_weekday__c from GW_Volunteers__Volunteer_Shift__c where id = :System.currentPagereference().getParameters().get('id')];
     
    public List<cContact> contactList {get; set;}

    
    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [Select c.ID, c.GW_Volunteers__Volunteer_Availability__c, c.GW_Volunteers__Volunteer_Status__c, c.Name, c.Volunteers_OK__c FROM Contact c WHERE c.Volunteers_OK__c = True and (c.GW_Volunteers__Volunteer_Availability__c INCLUDES (:stravail[0].Shift_weekday__c)) ]) {
                
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }


    public PageReference processSelected() {

                
        List<Contact> selectedContacts = new List<Contact>();

        for(cContact cCon : getContacts()) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
            }
        }

       
        System.debug('These are the selected Contacts...');
        for(Contact con : selectedContacts) {
            GW_Volunteers__Volunteer_Hours__c newvolu = new GW_Volunteers__Volunteer_Hours__c( GW_Volunteers__Contact__c = Con.id, GW_Volunteers__Volunteer_Job__c = stravail[0].GW_Volunteers__Volunteer_Job__c, GW_Volunteers__Volunteer_Shift__c = stravail[0].id, GW_Volunteers__Start_Date__c = system.today(), GW_Volunteers__Status__c = 'Scheduled', GW_Volunteers__Number_of_Volunteers__c = 1 );
            insert newvolu;
        
            system.debug(con);
        }
        return null;
    }


    public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}

        public cContact(Contact c) {
            con = c;
            selected = false;
        }
    }
}

 The VF Page:

<apex:page controller="wrapperClassController" showHeader="false">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Add Volunteers to shift" action="{!processSelected}" rerender="table" onclick="window.close()"/>
            </apex:pageBlockButtons>
            <br><b>
            Please check the Volunteers to be added to the Shift selected and press the "Add Volunteers to Shift" button.
            </b></br><br></br>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!contacts}" var="c" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!c.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!c.con.Name}" />
                <apex:column value="{!c.con.GW_Volunteers__Volunteer_Availability__c}" />
                <apex:column value="{!c.con.GW_Volunteers__Volunteer_Status__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 And Test Method (as far as I could go):

@isTest
private  class TestwrapperClassController
{
   static testMethod void testgetContacts()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     
      // insert a test contact
      List<Contact> con=new List<Contact>{new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Wednesday morning' ), 
            new Contact(FirstName='Lester2', Lastname='DbigTester2', accountID=acc.id, email='1231@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Friday morning')};
      insert con;

      PageReference pageRef = Page.Match_Availability;
       Test.setCurrentPageReference(pageRef);
       
      wrapperClassController stdCon=new wrapperClassController();
      system.debug('******TEST-stdCon='+ stdCon); 
           
      stdCon.contactList = stdCon.getcontacts();
      for (Integer i = 0; i < 3; i++) {
        system.debug('******TEST-getContacts[' + i + '].con=' + stdCon.ContactList[i].con);
    }
    System.assertEquals(true,stdCon.ContactList[1].con.Volunteers_OK__c);
    
      stdCon.ContactList[1].selected=True;  
           system.debug('******TEST-Contact 1 SELECT stdCon.ContactList[1].selected=' + 
        stdCon.ContactList[1].selected); 
        
         stdCon.processSelected();  
   
   }
}

 Thanks in advance and I really appreciatte any help! :)

B

Hi there,

 

working on a test method for a class that is a controller for a VF page and allows the user to check the box for the records they want and click on a button  to create new records on a diferent object, using the selected Contact records IDs.

Here is the Class:

 

 

public class wrapperClassController {
        
    GW_Volunteers__Volunteer_Shift__c[] stravail = [Select id, GW_Volunteers__Volunteer_Job__c, Shift_weekday__c from GW_Volunteers__Volunteer_Shift__c where id = :System.currentPagereference().getParameters().get('id')];
 
    public List<cContact> contactList {get; set;}

    
    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [Select c.ID, c.GW_Volunteers__Volunteer_Availability__c, c.GW_Volunteers__Volunteer_Status__c, c.Name, c.Volunteers_OK__c FROM Contact c WHERE c.Volunteers_OK__c = True and (c.GW_Volunteers__Volunteer_Availability__c INCLUDES (:stravail[0].Shift_weekday__c)) ]) {
                
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }


    public PageReference processSelected() {

                
        List<Contact> selectedContacts = new List<Contact>();

        
        for(cContact cCon : getContacts()) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
            }
        }

        
        System.debug('These are the selected Contacts...');
        for(Contact con : selectedContacts) {
            GW_Volunteers__Volunteer_Hours__c newvolu = new GW_Volunteers__Volunteer_Hours__c( GW_Volunteers__Contact__c = Con.id, GW_Volunteers__Volunteer_Job__c = stravail[0].GW_Volunteers__Volunteer_Job__c, GW_Volunteers__Volunteer_Shift__c = stravail[0].id, GW_Volunteers__Start_Date__c = system.today(), GW_Volunteers__Status__c = 'Scheduled', GW_Volunteers__Number_of_Volunteers__c = 1 );
            insert newvolu;
        
            system.debug(con);
        }
        return null;
    }

    public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}

        
        public cContact(Contact c) {
            con = c;
            selected = false;
        }
    }
}

 

 

I started to write a test method but got stuck when calling the class to test and don;t know how to make a record selected.:

 

 

@isTest
private  class TestwrapperClassController
{
   static testMethod void testgetContacts()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     
      // insert a test contact
      List<Contact> con=new List<Contact>{new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Wednesday morning' ), 
            new Contact(FirstName='Lester2', Lastname='DbigTester2', accountID=acc.id, email='1231@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Friday morning')};
      insert con;

      

         
       
      wrapperClassController tl=new wrapperClassController();
     
      List<Contact> ContactOK=tl.getContacts();
      tl.processSelected();

	
      
      System.assertEquals(0, ContactOK.size());
      
            
   }
}

 VF Page:

 

<apex:page controller="wrapperClassController" showHeader="false">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Add Volunteers to shift" action="{!processSelected}" rerender="table" onclick="window.close()"/>
            </apex:pageBlockButtons>
            <br><b>
            Please check the Volunteers to be added to the Shift selected and press the "Add Volunteers to Shift" button.
            </b></br><br></br>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!contacts}" var="c" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!c.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!c.con.Name}" />
                <apex:column value="{!c.con.GW_Volunteers__Volunteer_Availability__c}" />
                <apex:column value="{!c.con.GW_Volunteers__Volunteer_Status__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 

Any Help is really appreciated as usual. !

 

 

 

Hi,

I'm trying to build a query that will overcome the issue the TASK object and use it in Semi-joint queries. What I'm trying to do it to create a list and then, create another list on the same controler, where the records are NOT in the first list. here is the code:

 

private List<task> tskNO;
  public List<task> gettskNO()

    {
     candDate1=candDate-Integer.valueOf(rangedate);
    TAsk[] tskNO = [Select WhoID FROM task WHERE OwnerID = :UserInfo.getUserId() and createddate >= :candDate1];
    return tskNO;
    }

  private List<Contact> ContactNO;
  public List<Contact> getContactNO()
   {
Contact[] ContactNO = [Select c.id, c.AccountId from Contact c WHERE c.ID NOT IN :tskNO];
   return ContactNO;
   }

 

But I'm getting a "invalid binding" error on the "  :tskNO "  .

 

Is there a way to bind the criteria to another List on the controller?

 

Thanks!

Hi,

 

Trying to get the final part of this to work. I Have two Lists on thei VF page that control the values for the Criteria in the SOQL on the controller "TaskLeader". For the "Positions" list, I'm able to load the VF page fine and update the values and use the "Refresh" button to re-run the query. Now for the "rangedate" list, whatever value I select, it is still defaulting to 30 (days).

 

 

<apex:page controller="Taskleader" showHeader="false" >
<apex:form >
<apex:pageBlock id="pageBlock" Title="Activities logged">
<apex:pageMessages ></apex:pageMessages>
<apex:selectList id="Positions" value="{!positions}" size="1" title="Select Position">
<apex:selectoption itemLabel="President" itemValue="President"></apex:selectoption>
<apex:selectoption itemLabel="Co-President" itemValue="Co-President"></apex:selectoption>
</apex:selectList>
<apex:selectList id="rangedate" value="{!rangedate}" size="1" title="Last X Days">
<apex:selectoption itemLabel="30" itemValue="30"></apex:selectoption>
<apex:selectoption itemLabel="60" itemValue="60"></apex:selectoption>
<apex:selectoption itemLabel="90" itemValue="90"></apex:selectoption>
</apex:selectList>
<apex:commandButton action="{!Refreshtsk}" value="Run Report" />
<apex:pageBlockTable value="{!tsk}" var="tskl" rendered="{!NOT(ISNULL(tsk))}">
<apex:column headerValue="Name" ><apex:outputLink value="/{!tskl.who.id}" target="_parent">{!tskl.who.Name}

</apex:outputLink></apex:column>
<apex:column headerValue="Subject" ><apex:outputLink value="/{!tskl.id}" target="_parent">{!tskl.subject}

</apex:outputLink></apex:column>
<apex:column value="{!tskl.Activity_Type__c}"></apex:column>
<apex:column value="{!tskl.status}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>

</apex:page>

 

public class Taskleader
{

    public PageReference Refreshtsk() {
        return null;
    }

 
  public String positions {get; set;}
  public String rangedate {
           get {
            if (rangedate == null) rangedate = '30' ;
            return rangedate;
        }
        set;
    }

  Date candDate=System.today();
  Date candDate1=candDate-Integer.valueOf(rangeDate);


  private List<task> tsk;
  public List<task> gettsk()

    {
    TAsk[] tsk = [select id, subject, who.name, status, Activity_type__C, activitydate, what.name, Account.BillingCity, Account.BillingState FROM Task WHERE WhoID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE Position__c = :positions and  (Thru_Date__c = null OR Thru_Date__c > :system.today()) and (Start_Date__C <= :system.today()) ) and OwnerID = :UserInfo.getUserId() and createddate >= :candDate1];
    return tsk;
    }
}

 on the  "public String rangedate"  I had t use the "IF" statement as the VF page is loaded through a link and the value for the "rangedate" can't be null when the page is loaded. The problem is that after the page is loaded, regardless of the value selected for the rangedate, it is still defaulting to 30.  Had a good help on other issues on this page yesterday and appreciate any inputs..

 

Thanks,

B

 

Hi There,

 

I'm trying to get the value from a Selectlist in my VF page to my controller "Task_Leadership". The VF page works fine and the "refresh" button works good too. BUt, I can;t get the value from the SelectList with the ID = "Positions" to my controller. I've tried " ApexPages.currentPage().getParameters().get('Positions');" and no success. Here is the Page and Class:

 

 

<apex:page controller="Taskleader" showHeader="false" >
<apex:form >
<apex:pageBlock id="pageBlock" Title="Activities logged with Presidents in the Last 90 days">
<apex:pageMessages ></apex:pageMessages>
<apex:selectList id="Positions" size="1">
<apex:selectoption itemLabel="President" itemValue="President"></apex:selectoption>
<apex:selectoption itemLabel="Co-President" itemValue="Co-President"></apex:selectoption>
<apex:selectoption itemLabel="Education director" itemValue="Education director"></apex:selectoption>
</apex:selectList>
<apex:commandButton action="{!Refreshtsk}" value="Run Report" />
<apex:pageBlockTable value="{!tsk}" var="tskl" rendered="{!NOT(ISNULL(tsk))}">
<apex:column headerValue="Name" ><apex:outputLink value="/{!tskl.who.id}" target="_parent">{!tskl.who.Name}
</apex:outputLink></apex:column>
<apex:column headerValue="Subject" ><apex:outputLink value="/{!tskl.id}" target="_parent">{!tskl.subject}
</apex:outputLink></apex:column>
<apex:column value="{!tskl.Activity_Type__c}"></apex:column>
<apex:column value="{!tskl.status}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

public class Taskleader
{

    public PageReference Refreshtsk() {
        return null;
    }

  String POS = ApexPages.currentPage().getParameters().get('Positions');
  private List<task> tsk;
  public List<task> gettsk()

    {
    TAsk[] tsk = [select id, subject, who.name, status, Activity_type__C, activitydate, what.name, Account.BillingCity, Account.BillingState FROM Task WHERE WhoID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE Position__c = :POS and  (Thru_Date__c = null OR Thru_Date__c > :system.today()) and (Start_Date__C <= :system.today()) ) and OwnerID = :UserInfo.getUserId() and createddate >= :system.today()-90];
    return tsk;
    }
}

 

 

Thanks as usual!!

 

Hi there,

 

I'm having this error on my VF page and can't  get it resolved. here is the class and page:

 

 

    TAsk[] tsk = [select subject, who.name, status, type, activitydate, what.name FROM Task WHERE WhoID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE Position__c = 'President') and OwnerID = :UserInfo.getUserId()];
    return tsk;

 

<apex:page controller="Taskleader" showHeader="false" >
<apex:form >
<apex:pageBlock id="pageBlock" Title="Tasks with Presidents">
<apex:pageBlockTable value="{!tsk}" var="tskL" rendered="{!NOT(ISNULL(tsk))}">
<apex:column headerValue="Name" ><apex:outputLink value="https://cs2.salesforce.com/{!tsk.Who.id}" target="_parent">{!tsk.Who.Name}</apex:outputLink></apex:column>
<apex:column value="{!tsk.subject}"></apex:column>
<apex:column value="{!tsk.type}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Thanks!

 

Hello there,

 

I'm trying to get this trigger to work and for the part that  updates the Lead fields based on the Event data, is working fine. What I need to add is that if the Event Start date (startdatetime) that is being created/edited matches (same date same time and same ownerID) an Event already saved for the same Owner (Assigned to), an error on the page would display and the Leads would NOT get updated.

 

In other words, I'm trying to avoid an user booking an event that he/she already have another event scheduled on the same date. IF so, the new event date won;t be saved and the fields on the lead will NOT get updated. Here is my code (or the attempts..lol):

 

trigger tourchangeschedule1 on Event (before insert, after update) {
    
    Set<Id> recordIds = new Set<Id>();
    Set<id> eventidhold = New Set<id>();
    Set<id> ownertour = New set<id>();
    Set<string> tdate = New Set<string>();
    
    for ( Event  t : Trigger.New ) {
        if(t.subject=='tour' && t.Stages__c <> '30 days' && t.Stages__c <> '60 days'){
            recordIds.add(t.whoid);
            eventidhold.add(t.Id);
        ownertour.add(t.ownerid);
        tdate.add(t.startdatetime);

        }
    }
    
    List<Event> tourtaken = [select id from event where ownerid in :ownertour and startdatetime = :tdate];
    for ( Event  J : Trigger.New ) {
    IF (tourtaken.size()>0){ 
    a.adderror('There is a tour already scheduled for that time');
    }
    }
    
 
}
    
    List<lead> leadsOfEvents = [select id from lead where id in :recordIds];

    Map < Id ,lead > leadmap = new Map < Id , lead >();

    for ( lead  l : leadsOfEvents   ) {
        leadmap.put( l.Id, l);
    }

    List < lead > leadsToUpdate = new List < lead >();
     
    for(Event e: Trigger.New) {
        lead lc = leadmap.get( e.WhoID );
            
        if ( lc == null ) {
            
            continue;
        }
        
        lc.sales_cycle__C = 'Tour Scheduled';
        lc.tour_scheduled__C = e.StartDateTime;
        leadsToUpdate.add(Lc);
        
    }

    upsert leadsToUpdate;       

}

 

as usual, thanks for the good help!

B

 

Hi There,

 

I have the trigger bellow working fine, but now I need to check, before the trigger updates the Lead from an Event, If the Event being created/updated has a "Start Date" that will match another possible event, already scheduled for the same user (Assigned to) with the same "Start Date". It should not let the user create the event and an Alert should come up saying that "there is another Event already scheduled for you on that same date/time".

 

Here is the Trigger:

 

trigger tourchangeschedule on Event (before insert, after update) {
    
    Set<Id> recordIds = new Set<Id>();
    Set<id> eventidhold = New Set<id>();
    Set<Id> tourownerid = new Set<Id>();
    
    for ( Event  t : Trigger.New ) {
        if(t.subject=='tour' && t.Stages__c <> '30 days' && t.Stages__c <> '60 days'){
            recordIds.add(t.whoid);
            eventidhold.add(t.Id);
	    tourownerid.add(t.ownerid);
        }
    }

    
    List<lead> leadsOfEvents = [select id from lead where id in :recordIds];

    Map < Id ,lead > leadmap = new Map < Id , lead >();

    for ( lead  l : leadsOfEvents   ) {
        leadmap.put( l.Id, l);
    }

    List < lead > leadsToUpdate = new List < lead >();
     
    for(Event e: Trigger.New) {
        lead lc = leadmap.get( e.WhoID );
            
        if ( lc == null ) {
            
            continue;
        }
        
        lc.sales_cycle__C = 'Tour Scheduled';
        lc.tour_scheduled__C = e.StartDateTime;
        leadsToUpdate.add(Lc);
        
    }

    upsert leadsToUpdate;       

}

 

I though i adding the list:  List <event> toursbooked = [Select id from event where ownerid in :tourownerid and startdatetime = e.startDateTime]

 

IF "toursbooked" finds a match then "You already have a n event scheduled for the date/time"

Else

 

Proceed with the lead update as the code above, starting at "List<lead> leadsOfEvents..."

 

 

Thanks fot the help!

Hi there,

 

I have an error popping up saying " missing ; befor statement ".

I've looked at it several times but can't seem to find where is the missing ";" (semicolon) should be.

 

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

var result = sforce.connection.query("Select Id From Event where subject = 'Tour' and whoid = '{!Lead.Id}' ");
var records = result.getArray("records");

if (records.length == 0){
window.navigate("https://tapp0.salesforce.com/00U/e?who_id={!Lead.Id}&evt1_lkid=005A0000000IHh8&evt1=Philip+jones&evt5=Tour&evt12=Morgan_Ave&IsReminderSet=1&retURL=%2F{!Lead.Id}");
}
Else{
alert ("There is already a Tour Scheduled for this Lead. Please update the existing Scheduled Tour.");
}

 Thanks for the help!

Hi there,

 

Is it possible to create a button in the Event object that woulp appear on the edit screen of the Event. Just like the "Save" button appears. NOT on the default Event screen where the "edit" button is.

 

What i'm trying to do is to "mock" the "save" button for the event and create an option for the user to "Save" only the record or 'Save and Send email", without having to use a checkbox on the Event record.

 

Is there a way to do this without having to create a Visualforce page and then add the buttons there ?

 

Thanks a lot!

B

I'm trying to get the value of a custom field that is on the current page (Account) where I have a VF page within.

 

I'm using this:

 

public class KeyL
{

 String strname = Apexpages.currentPage().getParameters().get('Congregation_ID__C');
  private List<Leadership_position_code__c> LeadersL;
  public List<Leadership_position_code__c> getLeadersL()
    
    

    {
      LeadersL = [ Select l.Contact__c, l.Contact__r.AccountId from Leadership_Position_Code__c l WHERE (Congregation_code__C = :strname )];
            
           return LeadersL;
    }
            
}

 

I can't get the value from my Custom Field (Congregation_ID__C) into the String strname.

 

 

Thanks!

B

Hello there,

 

I'm getting 70% coverage with the test below, to a class working as a controller to a VF page. Dunno what am I missing and the allways good help is appreciated! :)

 

Class:

public class KeyLeadership
{

 
  private List<Leadership_position_code__c> Leaders;
  public List<Leadership_position_code__c> getLeaders()
    
    

    {
      Leaders = [ Select l.Contact__c, l.Contact__r.AccountId,  l.Contact__r.Email, l.Contact__r.Name, l.Position__c, l.Start_Date__c, l.Thru_Date__c from Leadership_Position_Code__c l WHERE (Contact__r.AccountId = :ApexPages.currentPage().getParameters().get('id') ) and 

    (l.Thru_Date__c = null OR l.Thru_Date__c > :system.today()) and ( l.Position__c = 'President' OR l.Position__c = 'Education Director' OR l.Position__c = 

'Co-President' OR l.Position__c = 'Senior (or only) Rabbi' OR l.Position__c = 'Administrator/Exec director' )
            ];
            
            system.debug('%%%%%%%%%55555'  + leaders.size());
     return Leaders;
    }
            
}

 

TEst Class:

@isTest
private  class TestKeyLeadership
{
   static testMethod void testGetLeaders()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     

      Contact con=new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com');
      insert con;

      List<leadership_position_code__c> LDS=new List<leadership_position_code__c>{new leadership_position_code__c(Contact__C=con.id, position_type__C='Clergy', Position__C='Cantor', Start_Date__C= system.Today()-2, Thru_date__C= system.Today()-1 ),
       new leadership_position_code__c(Contact__C=con.id, position_type__C='Officer', Position__C='President', Start_Date__C= system.Today()-1 ), 
       new leadership_position_code__c(Contact__C=Con.id, position_type__C='Clergy', Position__C='Senior (or only) Rabbi', Start_Date__C=system.Today()-1 )};
      insert LDS;
     
      ApexPages.currentPage().getParameters().put('id', acc.id);


      // instantiate the class under test
      KeyLeadership kl=new KeyLeadership();
     
      List<Leadership_Position_code__c> leaders=kl.getLeaders();

      // change the number below to the number of leadership_position_code__c objects created above
      System.assertEquals(2, leaders.size());

      // should also assert that the inserted records above match those retrieved.
      Leadership_position_code__C[] LDSok = [select id,position__C from Leadership_position_code__C where id in :leaders];
    System.assertEquals('President',LDSok[0].Position__c);
    System.assertEquals('Senior (or only) Rabbi',LDSok[1].Position__c);
      
      
   }
}

 

Thanks in advance!

B

 

Hi,

 

might be simple but I'm trying to reference this new contact with the test account created, this is a test for a controller.

on the NEW contact "con", I need it to be related to the account acc that I've just created. I'm trying account.name='xxxx" but doesn;' work.

 

@isTest
private class TestKeyLeadership
{
   static testMethod void testGetLeaders()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      insert acc;
      // insert a test Contact
      Contact con=new Contact(FirstName='Lester', Lastname='DbigTester', account=acc.id, email='123123123@888555.com');
      insert con;
      // insert a test Leadership Code
      List<leadership_position_code__c> LDS=new List<leadership_position_code__c>{new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Clergy', Position__C='Cantor', Start_Date__C='01/01/2011', Thru_date__C='01/02/2011' ),
       new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Officer', Position__C='President', Start_Date__C='01/01/2011' ), 
       new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Clergy', Position__C='Senior (or only) Rabbi', Start_Date__C='01/01/2011' )};
      insert LDS;
     
      // add the id to the current page
      ApexPages.currentPage.getParameters().put('id', acc.id);

      // instantiate the class under test
      KeyLeadership kl=new KeyLeadership();
     
      List<Leadership_Position_code__c> leaders=kl.getLeaders();

      System.assertEquals(2, leaders.size());
 
   }

 

Thanks!

B

Hi there..

HAve to build a time based workflow rule that will send an email, 01 day after the Lead created date, BUT, it has to be at 10AM.

Pretty much, I ahve the rule figured out for leads created between 9AM and 05PM EST. but I wanted the time based WF rule to send an email, IF NOT in between 9AM to 5PM, on  CreatedDate +1 but at 10AM.

 

Example:

 

Lead created at  01/20/2011 at  11AM

It is between 9am and 5pm, SO, send email.

 

Lead created at 01/20/2011  at  07PM

NOT between 9am and 5pm, SO, send email on 01/21/2011 at 10AM

 

Any ideas?

 

Thanks!

B

I've searched a bit and found some posts about using the IF statement within a VF page, but wasn;t clear about the possibility of using it for a simple display of a html page.

 

The controller is the standard ACCOUNT object.

All I need is something like this:

 

<apex:page standardController="account">
{!IF(isnull(account.JOB__c),"No Job","

<html>

some HTML coding here....

</html>"
)
}
</apex:page>

 The syntax is probably wrong, but I was wondering if this is possible.

 

Thanks in advance!

B

IS there a way to export the recycle bin to CSV or something like that ? 

I need to look at the details of some deleted records but I do not want to restore the record to the database.

 

Thanks for the help!

Breno

Hello!

 

I want to change a value on a SelectList item in a VF page I have named "Task_Type". The selectList is:

 

<apex:selectList id="rangedate" value="{!rangedate}" size="1" >
<apex:selectoption itemLabel="30" itemValue="30"></apex:selectoption>
<apex:selectoption itemLabel="60" itemValue="60"></apex:selectoption>
<apex:selectoption itemLabel="90" itemValue="90"></apex:selectoption>
<apex:selectoption itemLabel="180" itemValue="180"></apex:selectoption>
</apex:selectList>

I want to pick another value of that list so that i can increase the coverage on my test Method. I can call the page through:

 

    PageReference pageRef = Page.Task_type;      


but I'm having a hard time with the syntax in how to set the value of "rangedate" to "30" for example. Thanks for the HELP!

  • September 14, 2011
  • Like
  • 0

Hi All,

 

I have a requirement where I need to update some fields of opportunity. I have another custom object  with many fields( apprx 10000 records). Now I need to update fields of oportunity with the filds of custom object. Records are already present in both the object. What would be the best solution for this.

 

Thanks in advance!

 

Regards

Alok 

Hi there,

 

I have this VF page that runs a report based on the select list criteria. I had the class and test class working fine, until I had to add the option "All" onm the selectlist and , therefore, modify the controller for the new value. Got the controller to work but on my test class, I'm having a problem in testing exactly the ELSE statements. I think because that requires me to test the class also with other values from the selectlist.

 

Any help is appreciated! Here goes the Class, page and test class: (I've made the lines not covered on the class underlined and italic.)

 

public class TaskLeaderNO
{ 
    public PageReference Refreshtsk() {
        return page.Task_LeadershipNO;
    }
    
     public PageReference toexcel() {
        return page.Task_LeadershipXLSNO;
    }
     
  public String positions {get; set;}
  public String rangedate {get; set;}
  public String tasktype {get; set;}
  
  Date candDate;
  Date candDate1;

  public TaskLeaderNO()
  {
     rangedate='30';
     candDate=System.today(); 
     tasktype='All';  
     positions='All';   
  }

   Set<Id> tskNo = new Set<Id>();
 
  private List<Contact> ContactNO;
  public List<Contact> getContactNO()
   {
   candDate1=System.today()-Integer.valueOf(rangedate);
   tskNo = new set<ID>();
   
   IF (tasktype == 'All') {
   for (Task t: [Select WhoID FROM task WHERE OwnerID = :UserInfo.getUserId() and activitydate >= :candDate1])
   tskNo.add(t.WhoID);   
     } else {
 for (Task t: [Select WhoID FROM task WHERE OwnerID = :UserInfo.getUserId() and activitydate >= :candDate1 and type= :tasktype]) tskNo.add(t.WhoID); }   
   
    IF (positions == 'All') {
  
   Contact[] ContactNO = [Select id, AccountId, Account.name, Email, Name, account.billingcity, account.billingstate from Contact 

WHERE ID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE (Position__c = 'President' OR Position__c = 'Education Director' OR 

Position__c ='Co-President' OR Position__c = 'Senior (or only) Rabbi' OR Position__c = 'Administrator/Exec director') and  (Thru_Date__c = 

null OR 

Thru_Date__c > :system.today()) and (Start_Date__C <= :system.today()) ) and account.Congregational_Rep__c = :UserInfo.getUserId() 

and ID NOT IN :tskNO];
   return ContactNO;
    } else {

 Contact[] ContactNO = [Select id, AccountId, Account.name, Email, Name, account.billingcity, account.billingstate from Contact WHERE ID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE Position__c = :positions and (Thru_Date__c = null OR Thru_Date__c > :system.today()) and (Start_Date__C <= :system.today()) ) and account.Congregational_Rep__c = :UserInfo.getUserId() and ID NOT IN :tskNO]; return ContactNO;

     }
   }

}

 

Page:

<apex:page controller="TaskLeaderNO" showHeader="false" >
<apex:form >
<apex:pageBlock id="pageBlock" Title="NO Activities with Key Leadership">
<apex:pageMessages ></apex:pageMessages>
<b>Select Position:   </b>
<apex:selectList id="Positions" value="{!positions}" size="1">
<apex:selectoption itemLabel="All" itemValue="All"></apex:selectoption>
<apex:selectoption itemLabel="President" itemValue="President"></apex:selectoption>
<apex:selectoption itemLabel="Co-President" itemValue="Co-President"></apex:selectoption>
<apex:selectoption itemLabel="Senior (or only) Rabbi" itemValue="Senior (or only) Rabbi"></apex:selectoption>
<apex:selectoption itemLabel="Administrator/Exec Director" itemValue="Administrator/Exec Director"></apex:selectoption>
<apex:selectoption itemLabel="Education director" itemValue="Education director"></apex:selectoption>
</apex:selectList>
<b> How many days back? </b>
<apex:selectList id="rangedate" value="{!rangedate}" size="1" >
<apex:selectoption itemLabel="30" itemValue="30"></apex:selectoption>
<apex:selectoption itemLabel="60" itemValue="60"></apex:selectoption>
<apex:selectoption itemLabel="90" itemValue="90"></apex:selectoption>
<apex:selectoption itemLabel="180" itemValue="180"></apex:selectoption>
</apex:selectList>
<b>   </b>
<b> Activity Type </b>
<apex:selectList id="tasktype" value="{!tasktype}" size="1" >
<apex:selectoption itemLabel="All" itemValue="All"></apex:selectoption>
<apex:selectoption itemLabel="Phone Call" itemValue="Phone Call"></apex:selectoption>
<apex:selectoption itemLabel="Email" itemValue="Email"></apex:selectoption>
</apex:selectList>
<b>   </b>
<apex:commandButton action="{!Refreshtsk}" value="Run Report" />
<b>   </b>
<apex:commandButton action="{!toexcel}" value="Export to Excel" />
<apex:pageBlockTable value="{!ContactNO}" var="cont" rendered="{!NOT(ISNULL(ContactNO))}" id="tblContactNo">
<apex:column headerValue="Name" ><apex:outputLink value="/{!cont.id}" target="_parent">{!cont.Name}
</apex:outputLink></apex:column>
<apex:column value="{!cont.Email}"></apex:column>
<apex:column headerValue="Congregation" value="{!cont.account.name}"></apex:column>
<apex:column value="{!cont.account.billingcity}"></apex:column>
<apex:column value="{!cont.account.billingstate}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>

</apex:page>

 And test:

 

@isTest
private  class TestTaskleaderNO
{
   static testMethod void testgetContactNO()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     
      // insert a test contact
      List<Contact> con=new List<Contact>{new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com', Key_Contact__C = True), 
            new Contact(FirstName='Lester2', Lastname='DbigTester2', accountID=acc.id, email='2222222@22225.com', Key_Contact__C = True)};
      insert con;

      // insert some test leadership codes
      List<leadership_position_code__c> LDS=new List<leadership_position_code__c>{new leadership_position_code__c(Contact__C=con[0].id, position_type__C='Officer', Position__C='President', Start_Date__C= system.Today()-1 )};
      insert LDS;

    List<task> tasks = new List<task>{ new task(WhoId=con[0].Id,Subject='HEllo Task',ActivityDate=System.today()-10, activity_type__C = 'Email', Priority = 'Normal', Status = 'In Progress' ),
                                        new task(WhoId=con[1].Id,Subject='HEllo Task2',ActivityDate=System.today()-12, activity_type__C = 'Email', Priority = 'Normal', Status = 'In Progress' )   };
    insert tasks;


      // captures the acc id for the page     
      


      // instantiate the class under test
      TaskLeaderNO tl=new TaskLeaderNO();
     
      List<Contact> ContOK=tl.getContactNO();
      tl.refreshtsk();
      tl.toexcel();

      // change the number below to the number of leadership_position_code__c objects created above
      System.assertEquals(0, ContOK.size());
      
            
   }

 Thanks again!

 

B

 

  • September 09, 2011
  • Like
  • 0

Hi there,

 

still strugling with the test method for this wrapperclass as I can't pass 30% coverage. HAd some good help but still fighting it! :)

 

Here is the class:

 

public class wrapperClassController {
        
    GW_Volunteers__Volunteer_Shift__c[] stravail = [Select id, GW_Volunteers__Volunteer_Job__c, Shift_weekday__c from GW_Volunteers__Volunteer_Shift__c where id = :System.currentPagereference().getParameters().get('id')];
     
    public List<cContact> contactList {get; set;}

    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [Select c.ID, c.GW_Volunteers__Volunteer_Availability__c, c.GW_Volunteers__Volunteer_Status__c, c.Name, c.Volunteers_OK__c FROM Contact c WHERE c.Volunteers_OK__c = True and (c.GW_Volunteers__Volunteer_Availability__c INCLUDES (:stravail[0].Shift_weekday__c)) ]) {
                // As each contact is processed we create a new cContact object and add it to the contactList
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }

    public PageReference processSelected() {

                
        List<Contact> selectedContacts = new List<Contact>();

        for(cContact cCon : getContacts()) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
            }
        }

        System.debug('These are the selected Contacts...');
        for(Contact con : selectedContacts) {
            GW_Volunteers__Volunteer_Hours__c newvolu = new GW_Volunteers__Volunteer_Hours__c( GW_Volunteers__Contact__c = Con.id, GW_Volunteers__Volunteer_Job__c = stravail[0].GW_Volunteers__Volunteer_Job__c, GW_Volunteers__Volunteer_Shift__c = stravail[0].id, GW_Volunteers__Start_Date__c = system.today(), GW_Volunteers__Status__c = 'Scheduled', GW_Volunteers__Number_of_Volunteers__c = 1 );
            insert newvolu;
        
            system.debug(con);
        }
        return null;
    }

    public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}

        
        public cContact(Contact c) {
            con = c;
            selected = false;
        }
    }
}

 And the test Method:

 

@isTest
private  class TestwrapperClassController
{
   static testMethod void testgetContacts()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     
      // insert a test contact
      List<Contact> con=new List<Contact>{new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Wednesday morning' ), 
            new Contact(FirstName='Lester2', Lastname='DbigTester2', accountID=acc.id, email='1231@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Friday morning')};
      insert con;
      
     Campaign  CP = new Campaign ( name='TESTCPG' );
     insert CP ;

    GW_Volunteers__Volunteer_Job__c  GMVjob = new GW_Volunteers__Volunteer_job__c ( Name='Testjob', GW_Volunteers__Campaign__c=CP.id );
    insert GMVjob ;

    GW_Volunteers__Volunteer_Shift__c  GMVShift = new GW_Volunteers__Volunteer_Shift__c ( GW_Volunteers__Volunteer_Job__c=GMVjob.id , GW_Volunteers__Start_Date_Time__c =System.now(), GW_Volunteers__Duration__c = 3);
    insert GMVShift ;
      
    PageReference pageRef = Page.Match_Availability;       
    pageRef.getParameters().put('id' , GMVShift.id);
    Test.setCurrentPageReference(pageRef);

       
      wrapperClassController stdCon=new wrapperClassController();
      system.debug('******TEST-stdCon='+ stdCon); 
           
      stdCon.contactList = stdCon.getcontacts();
      for (Integer i = 0; i < 3; i++) {
        system.debug('******TEST-getContacts[' + i + '].con=' + stdCon.ContactList[i].con);
    }
    System.assertEquals(true,stdCon.ContactList[1].con.Volunteers_OK__c);
    
      stdCon.ContactList[1].selected=True;  
           system.debug('******TEST-OPPORTUNITY 1 SELECT stdCon.ContactList[1].selected=' + 
        stdCon.ContactList[1].selected); 
        
         stdCon.processSelected();  
         
    
   }
}

 HELP! :)

Hi there,

 

Posted before here an issue I'm having with a test method and, after looking at it I've noticed the List index out of bounds: 0. Thats because of a criteria on my SOQL statement that reads : 

 

(c.GW_Volunteers__Volunteer_Availability__c INCLUDES (:stravail[0].Shift_weekday__c)) 

 

Well, the Shift_weekday__c is on another SOQL that pulls the record ID from the current page that the user is in. The controller (wrapperclasscontroller) was built so that the user hits a button from a page and it pulls a report based on the Shift_weekday__c from the current record on the page the user is hitting the button from. The report comes up and gives the user check boxes so that you can chose the records and hit a button that will create records on a diferent object (Not the CONTACT) using the current contact IDs.

 

MY issue is How do I call the page and set some test Shift_weekday__c from the test method, just so that when I call the getcontacts() , my List does not return 0 (zero) records. The test method is really where I'm stuck.

 

Here is the controller:

 

public class wrapperClassController {
        
    GW_Volunteers__Volunteer_Shift__c[] stravail = [Select id, GW_Volunteers__Volunteer_Job__c, Shift_weekday__c from GW_Volunteers__Volunteer_Shift__c where id = :System.currentPagereference().getParameters().get('id')];
     
    public List<cContact> contactList {get; set;}

    
    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [Select c.ID, c.GW_Volunteers__Volunteer_Availability__c, c.GW_Volunteers__Volunteer_Status__c, c.Name, c.Volunteers_OK__c FROM Contact c WHERE c.Volunteers_OK__c = True and (c.GW_Volunteers__Volunteer_Availability__c INCLUDES (:stravail[0].Shift_weekday__c)) ]) {
                
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }


    public PageReference processSelected() {

                
        List<Contact> selectedContacts = new List<Contact>();

        for(cContact cCon : getContacts()) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
            }
        }

       
        System.debug('These are the selected Contacts...');
        for(Contact con : selectedContacts) {
            GW_Volunteers__Volunteer_Hours__c newvolu = new GW_Volunteers__Volunteer_Hours__c( GW_Volunteers__Contact__c = Con.id, GW_Volunteers__Volunteer_Job__c = stravail[0].GW_Volunteers__Volunteer_Job__c, GW_Volunteers__Volunteer_Shift__c = stravail[0].id, GW_Volunteers__Start_Date__c = system.today(), GW_Volunteers__Status__c = 'Scheduled', GW_Volunteers__Number_of_Volunteers__c = 1 );
            insert newvolu;
        
            system.debug(con);
        }
        return null;
    }


    public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}

        public cContact(Contact c) {
            con = c;
            selected = false;
        }
    }
}

 The VF Page:

<apex:page controller="wrapperClassController" showHeader="false">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Add Volunteers to shift" action="{!processSelected}" rerender="table" onclick="window.close()"/>
            </apex:pageBlockButtons>
            <br><b>
            Please check the Volunteers to be added to the Shift selected and press the "Add Volunteers to Shift" button.
            </b></br><br></br>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!contacts}" var="c" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!c.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!c.con.Name}" />
                <apex:column value="{!c.con.GW_Volunteers__Volunteer_Availability__c}" />
                <apex:column value="{!c.con.GW_Volunteers__Volunteer_Status__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 And Test Method (as far as I could go):

@isTest
private  class TestwrapperClassController
{
   static testMethod void testgetContacts()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     
      // insert a test contact
      List<Contact> con=new List<Contact>{new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Wednesday morning' ), 
            new Contact(FirstName='Lester2', Lastname='DbigTester2', accountID=acc.id, email='1231@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Friday morning')};
      insert con;

      PageReference pageRef = Page.Match_Availability;
       Test.setCurrentPageReference(pageRef);
       
      wrapperClassController stdCon=new wrapperClassController();
      system.debug('******TEST-stdCon='+ stdCon); 
           
      stdCon.contactList = stdCon.getcontacts();
      for (Integer i = 0; i < 3; i++) {
        system.debug('******TEST-getContacts[' + i + '].con=' + stdCon.ContactList[i].con);
    }
    System.assertEquals(true,stdCon.ContactList[1].con.Volunteers_OK__c);
    
      stdCon.ContactList[1].selected=True;  
           system.debug('******TEST-Contact 1 SELECT stdCon.ContactList[1].selected=' + 
        stdCon.ContactList[1].selected); 
        
         stdCon.processSelected();  
   
   }
}

 Thanks in advance and I really appreciatte any help! :)

B

Hi there,

 

working on a test method for a class that is a controller for a VF page and allows the user to check the box for the records they want and click on a button  to create new records on a diferent object, using the selected Contact records IDs.

Here is the Class:

 

 

public class wrapperClassController {
        
    GW_Volunteers__Volunteer_Shift__c[] stravail = [Select id, GW_Volunteers__Volunteer_Job__c, Shift_weekday__c from GW_Volunteers__Volunteer_Shift__c where id = :System.currentPagereference().getParameters().get('id')];
 
    public List<cContact> contactList {get; set;}

    
    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [Select c.ID, c.GW_Volunteers__Volunteer_Availability__c, c.GW_Volunteers__Volunteer_Status__c, c.Name, c.Volunteers_OK__c FROM Contact c WHERE c.Volunteers_OK__c = True and (c.GW_Volunteers__Volunteer_Availability__c INCLUDES (:stravail[0].Shift_weekday__c)) ]) {
                
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }


    public PageReference processSelected() {

                
        List<Contact> selectedContacts = new List<Contact>();

        
        for(cContact cCon : getContacts()) {
            if(cCon.selected == true) {
                selectedContacts.add(cCon.con);
            }
        }

        
        System.debug('These are the selected Contacts...');
        for(Contact con : selectedContacts) {
            GW_Volunteers__Volunteer_Hours__c newvolu = new GW_Volunteers__Volunteer_Hours__c( GW_Volunteers__Contact__c = Con.id, GW_Volunteers__Volunteer_Job__c = stravail[0].GW_Volunteers__Volunteer_Job__c, GW_Volunteers__Volunteer_Shift__c = stravail[0].id, GW_Volunteers__Start_Date__c = system.today(), GW_Volunteers__Status__c = 'Scheduled', GW_Volunteers__Number_of_Volunteers__c = 1 );
            insert newvolu;
        
            system.debug(con);
        }
        return null;
    }

    public class cContact {
        public Contact con {get; set;}
        public Boolean selected {get; set;}

        
        public cContact(Contact c) {
            con = c;
            selected = false;
        }
    }
}

 

 

I started to write a test method but got stuck when calling the class to test and don;t know how to make a record selected.:

 

 

@isTest
private  class TestwrapperClassController
{
   static testMethod void testgetContacts()
   {
      // insert a test account
      Account acc=new Account(Name='Test123');
      Database.saveresult sr = database.insert(acc);
     
      // insert a test contact
      List<Contact> con=new List<Contact>{new Contact(FirstName='Lester', Lastname='DbigTester', accountID=acc.id, email='123123123@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Wednesday morning' ), 
            new Contact(FirstName='Lester2', Lastname='DbigTester2', accountID=acc.id, email='1231@888555.com', Volunteers_OK__c  = True, GW_Volunteers__Volunteer_Availability__c = 'Friday morning')};
      insert con;

      

         
       
      wrapperClassController tl=new wrapperClassController();
     
      List<Contact> ContactOK=tl.getContacts();
      tl.processSelected();

	
      
      System.assertEquals(0, ContactOK.size());
      
            
   }
}

 VF Page:

 

<apex:page controller="wrapperClassController" showHeader="false">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Add Volunteers to shift" action="{!processSelected}" rerender="table" onclick="window.close()"/>
            </apex:pageBlockButtons>
            <br><b>
            Please check the Volunteers to be added to the Shift selected and press the "Add Volunteers to Shift" button.
            </b></br><br></br>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!contacts}" var="c" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!c.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!c.con.Name}" />
                <apex:column value="{!c.con.GW_Volunteers__Volunteer_Availability__c}" />
                <apex:column value="{!c.con.GW_Volunteers__Volunteer_Status__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 

Any Help is really appreciated as usual. !

 

 

 

Hi,

I'm trying to build a query that will overcome the issue the TASK object and use it in Semi-joint queries. What I'm trying to do it to create a list and then, create another list on the same controler, where the records are NOT in the first list. here is the code:

 

private List<task> tskNO;
  public List<task> gettskNO()

    {
     candDate1=candDate-Integer.valueOf(rangedate);
    TAsk[] tskNO = [Select WhoID FROM task WHERE OwnerID = :UserInfo.getUserId() and createddate >= :candDate1];
    return tskNO;
    }

  private List<Contact> ContactNO;
  public List<Contact> getContactNO()
   {
Contact[] ContactNO = [Select c.id, c.AccountId from Contact c WHERE c.ID NOT IN :tskNO];
   return ContactNO;
   }

 

But I'm getting a "invalid binding" error on the "  :tskNO "  .

 

Is there a way to bind the criteria to another List on the controller?

 

Thanks!