• Nervosa
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 31
    Replies

Hi to everyone out there!

 

I've got an issue with turning Chatter off. There are such declarations in my controller in test method:

 

CollaborationGroup CgTest1 = new CollaborationGroup(Name = 'CgTest1', CollaborationType = 'Public');
		insert CgTest1;
		
		CollaborationGroup CgTest2 = new CollaborationGroup(Name = 'CgTest2', CollaborationType = 'Public');
		insert CgTest2;
		
		CollaborationGroupMember CgmTest1 = new CollaborationGroupMember(CollaborationGroupId = CgTest1.Id, MemberId = u.Id);
		insert CgmTest1;

 So when i'm trying to turn Chatter off the message being received - 

Cannot disable Chatter. It is referenced by the following components: 

I tried to put these declarations in try catch block - no results. I tried to make declarations only when 

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
if(gd.containsKey('FeedItem'))

gd.containsKey('FeedItem') == true - still the same message.

 

Is there any workaround for such issue?

 

Thanks in advance.

Greetings to everyone!

Here is a question. My APEX controller:

 

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   private String searchStr = ' order by ';
   public Date searchDateCopy;
   public String searchTextCopy;
   public Boolean EndSearch { get; set; }
   public Boolean DelCopy { get; set; }
   public Boolean MakeCopy { get; set; }
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }
   public String searchText {get;set;}
   public Date searchDate { get; set; }
   public List<Item__c> searchResults {get;set;}
   
   public fullfunctionality_2() {

       ViewData();
   }

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate
                );
                insert NewItem; 
                ViewData();
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                NewItemName=null;
                NewItemQuantity=null;
                NewItemPrice = null;
                NewItemReleaseDate = null;
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;   
               
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();     
        return curPage;          
    }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
       if (DelCopy == true){
           searchDateCopy = null;
           searchTextCopy = null;}

       if (MakeCopy == true) {
           searchDateCopy = searchDate;
           searchTextCopy = searchText;
       }    
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       if(searchTextCopy != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchTextCopy + '%\' order by ';}
       if(searchDateCopy != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchTextCopy + '%\' and DAY_ONLY(CreatedDate) =:searchdatecopy order by ';}   
           
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c ' + searchstr + sortFullExp);
       

           searchText = null;
           searchDate = null;

       return null;
   }
}

 And here is a test class for controller:

 

@isTest
private class TestFullFunctionality_2 {

String NewItemName = 'NEWITEM';
Integer NewItemPrice = 100;
String NewItemType = 'Solid';
Integer NewItemQuantity = 10;

static testMethod void testAdd() {
TestFullFunctionality_2 ext;       
Item__c NewItem = new Item__c(name = 'NEWITEM', Item_Price__c = 100, Item_Type__c = 'Solid', Items_Available__c = 10 );
insert NewItem;
FullFunctionality_2 Con=new FullFunctionality_2();
Con.add();
Con.del();
Con.viewData();

}
}

 I still cannot understand - why do i get an error:

 

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Item_Price__c]: [Item_Price__c]

 Maybe someone can help me?

 

Thanks in advance.

Greetings to everybody out there!

So here is the question. There is a SOQL query that being formed like this:

       date mysearchdate=date.valueOf(searchDate);
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       if(searchText != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchText + '%\' order by ';}
       if(searchDate != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchText + '%\' and CreatedDate >=: mysearchdate order by ';}   
           
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c ' + searchstr + sortFullExp);

 Well, the main problem is in this -

CreatedDate >=: mysearchdate

part of code. It doesn't work when i need to perform accurate comparison:

CreatedDate =: mysearchdate

Why?

 

Thanks in advance.

Greetings to everyone!

 

I've got a problem that had most of you, i think =)

There is an inputtext on my VF page:

<apex:inputText value="{!NewItemReleaseDate}" id="rdate" label="Release Date" onfocus="DatePicker.pickDate(false, this, false);"/> 

 As you can see users enter date here.

Also there is a PageBlockSection that function as a search block:

        <apex:pageBlockSection title="Search an item by name and\or release date" collapsible="false">      
        <apex:pageBlockSectionItem >
        <apex:panelGrid >
          <apex:outputLabel style="float:left">Name</apex:outputLabel>
              <apex:inputText id="searchText" value="{!searchText}" style="float:left"/>
          <apex:outputLabel style="float:left" >Date</apex:outputLabel>  
          <apex:inputText id="searchDate" value="{!searchDate}" onfocus="DatePicker.pickDate(false, this, false);" style="float:left">
              <apex:param value="{0,date,MM/dd/yyyy}" assignTo="{!searchDate}"/>    
          </apex:inputText>          
          <apex:commandButton id="SearchButton" value="Search" action="{!ViewData}" reRender="FullFunctionalityForm">
              <apex:param value="WHERE name=" assignTo="{!searchStr}"/>
              <apex:param value="" assignTo="{!searchDate}"/>
          </apex:commandButton>
        </apex:panelGrid>
        </apex:pageBlockSectionItem>
      </apex:pageBlockSection>

 Here is a search method from my APEX controller:

   public PageReference ViewData() {
   
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       if(searchText != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchText + '%\' order by ';}
       if(searchDate != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchText + '%\' and CreatedDate =: searchDate  order by ';}              
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c ' + searchstr + sortFullExp);

       return null;
   }

 ...and it doesn't work!!! =(

I guess that my issue concerns date formats both that entered when user adds new item and when searching one.

 

Help me please!

 

Thanks in advance.

Greetings to everyone!

 

Strictly speaking - my question is in subject. I have a PageBlockTable on a VF page:

 

<apex:pageBlockTable value="{!items}" var="i" id="ListOfItems" >

 Is it possible to change its "value" attribute to another one by clicking a button:

 

 <apex:commandButton value="Search" action="{!search}" rerender="resultsBlock" status="status"/>

 Thanks in advance.

Greetings to everyone!

 

I've got a little question - what should i use in SOQL query for date type instead of LIKE? Maybe there some casting should be used?

 

The deal is - there is a query in my Apex controller:

String qry = 'select id, name, createddate, item_price__c from Item__c ' +
        'where name LIKE \'%'+searchText+'%\' and Release_Date__c LIKE \'%'+searchDate+'%\' order by name';

 Release_Date__c - date type of course.

 

Can you help me?

Hi there!

There is a little problem with using DatePicker in inputText component on a VF page. I implement it like this:

 

    <apex:inputText value="{!NewItemReleaseDate}"  label="Release Date" onfocus="DatePicker.pickDate(false, this, false);" />

 Calendar appears and date is picked well but it doesn't appear in inputText. Why? I can't see the solution. May be you do?

 

Thanks in advance.

Greetings to everyone!

 

I've got a problem writing test for my Apex controller. Here is controller:

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }
   public string searchText {get;set;}
   public List<Item__c> searchResults {get;set;}

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate);
                insert NewItem; 
                ViewData();
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                NewItemName=null;
                NewItemQuantity=null;
                NewItemPrice = null;
                NewItemReleaseDate = null;
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;   
               
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();
        curPage.setRedirect(false);       
        return curPage;
            
    }    

  public PageReference search() {
        String qry = 'select id, name, createddate, item_price__c from Item__c ' +
        'where name LIKE \'%'+searchText+'%\' order by name';
        searchResults = Database.query(qry);
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();
        curPage.setRedirect(true);       
        return null;        
  }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
   
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c order by ' + sortFullExp + ' limit 1000');
       return null;
   }
}

 I wrote a piece of test, it looks like this:

 

@isTest
private class TestFullFunctionality_2 {

static testMethod void testItemEnter() {

    Item__c NewItem = new Item__c(name = 'NEWITEM', Item_Price__c = 100, Item_Type__c = 'Solid', Items_Available__c = 10 );
    insert NewItem;
    Test.startTest();
    Test.stopTest();    
}
}

 ...but still the code coverage total is 0%. What do i do wrong?

 

Thanks in advance.

Hello!

The deal is - i've got 2 methods in my controller: the one to ADD:

 

   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate);
                insert NewItem; 
                ViewData();
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                return null; 
    }     

 and the second to DELETE:

   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;   
               
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();
        curPage.setRedirect(false);       
        return curPage;
            
    }    

 Also there is a set of inputText elements on my VF page:

 

    <apex:inputText value="{!NewItemName}" label="Name" style="text-align:left"/>
    <apex:selectList id="types" label="Type" size="1" value="{!NewItemType}">

            <apex:selectOptions value="{!types}">
                
            </apex:selectOptions>
        </apex:selectList>  
    <apex:inputText value="{!NewItemPrice}" label="Price" style="text-align:left" />
    <apex:inputText value="{!NewItemQuantity}" label="Quantity" style="text-align:left"/>
    <apex:inputText value="{!NewItemReleaseDate}"  label="Release Date"/>

 It all works pretty well but there is one problem - old values remain in inputText elements after an item is ADDED. So i want to refer to them after adding and assign zeros or NULL's them. Do you think i can do it?

 

Thanks in advance.

Greetings to everyone!

 

Look, here is my VF page:

<apex:page standardStylesheets="false" showHeader="false" sidebar="false" controller="Fullfunctionality_2">
<apex:stylesheet value="{!URLFOR($Resource.Styles, 'styles.css')}"/>
<apex:sectionHeader title="List of items in stock with ADD, DELETE, SORT and SEARCH functions"></apex:sectionHeader>
<apex:form >
<apex:pageBlock >
      <apex:commandButton value="Show items" action="{!ViewData}" >
      </apex:commandButton> 
    <apex:pageBlockTable value="{!items}" var="i" >
    <apex:column >
        <apex:commandLink action="{!del}" value="Delete">
            <apex:param name="idtodel" value="{!i.id}" assignTo="{!IDToDel}"/>
        </apex:commandLink>
    </apex:column>
       <apex:column style="text-align:left">
         <apex:facet name="header">   
           <apex:commandLink action="{!ViewData}" value="Item name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
             <apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputText value="{!i.name}"></apex:outputText>
       </apex:column>
       <apex:column style="text-align:left">
           <apex:facet name="header">
               <apex:commandLink action="{!ViewData}" value="Price{!IF(sortExpression=='Item_Price__c',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
                   <apex:param value="Item_Price__c" name="column" assignTo="{!sortExpression}"/>
               </apex:commandLink>
           </apex:facet>
           <apex:outputText value="{!i.Item_Price__c}"/>
       </apex:column>
       <apex:column >
           <apex:facet name="header">
               <apex:commandLink action="{!ViewData}" value="Adding date{!IF(sortExpression=='createddate',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
                   <apex:param value="createddate" name="column" assignTo="{!sortExpression}"/>
               </apex:commandLink>
           </apex:facet>
           <apex:outputText value="{0,date,MM/dd/yyyy}">
               <apex:param value="{!i.createddate}"/>
           </apex:outputText>
       </apex:column>
    </apex:pageBlockTable>
    <apex:pageBlockSection columns="1">
    <apex:inputText value="{!NewItemName}" label="Name" style="text-align:left"/>
    <apex:selectList id="types" size="1" required="true" label="Type" >
        <apex:selectOptions value="{!types}"/>
    </apex:selectList>
    <apex:inputText value="{!NewItemPrice}" label="Price" style="text-align:left" />
    <apex:inputText value="{!NewItemQuantity}" label="Quantity" style="text-align:left"/>
    <apex:inputText value="{!NewItemReleaseDate}"  label="Release Date"/>
    <apex:commandButton value="Add item" action="{!add}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 And its APEX controller:

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate);
                insert NewItem; 
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;                     
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        curPage.setRedirect(true);
        return curPage;
            
    }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
   
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c order by ' + sortFullExp + ' limit 1000');
       return null;
   }
}

 I have some questions.

1) As you can see there are such elements like pageBlockTable and pageBlockSection. When VF page is being rendered pageBlockSection is situated below pageBlockTable. And I want it to be situated to the right to pageBlockTable. How can i do it?

2) When i add or delete an item the page reloads and i see only header of pageBlockTable. The same occurs when i load page for the first time during the session. How can i avoid it?

 

Thanks in advance.

Greetings everyone!

Surfing over the Internet trying to find information about sorting on a VF pages i've found this - http://salesforcesource.blogspot.com/2008/11/adding-sorting-capability-to.html

and it was a desirable discovery BUT!! - it is ALMOST what i was searching for. The problem is that in my case there is a custom object. And that tutorial concerns only sObjects. Everything in it is applicable for my Item__c object except this part:

 

   public PageReference ViewData() {
       //build the full sort expression
       string sortFullExp = sortExpression  + ' ' + sortDirection;
      
       //query the database based on the sort expression
       accounts = Database.query('Select id, Name, BillingCity, BillingCountry, Phone from Account order by ' + sortFullExp + ' limit 1000');
       return null;
   }

 I don't see ways how can i do that with custom object. Please help me.

 

Thanks in advance.

Greetings to everyone!

 

On my VF i have a commandlink and it looks like this:

        <apex:commandLink value="Delete" action="{!del}">
            <apex:param name="idtodel" value={!pitem.merchandise.id}"/>
        </apex:commandLink>

 In my Apex controller i want to implement deletion like this:

    public PageReference del() {
    Id IdToDel=System.currentPageReference().getParameters().get('id');
    Item__c ItemToDel = [SELECT all
                         FROM Item__c
                         WHERE id = IdToDel];
    PageReference curPage = ApexPages.currentPage(); 
    curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        curPage.setRedirect(true);
        return curPage; 
            
    }

and i get an error "unexpected token: 'IdToDel' at line 7 column 40"

Hi there! =)

 

Look what i've got! Here is my Apex class:

 

public class FullFunctionality {

    public String NewItemName {get; set;}
    public Integer NewItemQuantity { get; set; }
    public Integer NewItemPrice { get; set; }
    public String NewItemType { get; set; }
    public Date NewItemReleaseDate { get; set; }



    public List<SelectOption> getTypes(){
        List<SelectOption> types = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
   {
      types.add(new SelectOption(f.getLabel(), f.getValue()));
   }       
   return types;
    }
    
    public void add() {
        
        Item__c NewItem = new Item__c(            
            Name = NewItemName,
            Item_Price__c = NewItemPrice,
            Items_Available__c = NewItemQuantity,
            Item_Type__c = NewItemType,
            Release_Date__c = NewItemReleaseDate);
        insert NewItem;    
    }
    
    DisplayMerchandise[] products;

    public class DisplayMerchandise {
        public Item__c merchandise { get; set; }
        public DisplayMerchandise(Item__c item) {
            this.merchandise = item;
        }
    }

    public DisplayMerchandise[] getProducts() {
        if (products == null) {
            products = new DisplayMerchandise[]{};
            for (Item__c item : 
                [SELECT id, name, item_price__c, createddate, item_type__c 
                 FROM Item__c ]) {
               products.add(new DisplayMerchandise(item));
             }
         }
     return products;      
    }
}

 and here is my VF page:

 

public class FullFunctionality {

    public String NewItemName {get; set;}
    public Integer NewItemQuantity { get; set; }
    public Integer NewItemPrice { get; set; }
    public String NewItemType { get; set; }
    public Date NewItemReleaseDate { get; set; }



    public List<SelectOption> getTypes(){
        List<SelectOption> types = new List<SelectOption>();
        Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
   {
      types.add(new SelectOption(f.getLabel(), f.getValue()));
   }       
   return types;
    }
    
    public void add() {
        
        Item__c NewItem = new Item__c(            
            Name = NewItemName,
            Item_Price__c = NewItemPrice,
            Items_Available__c = NewItemQuantity,
            Item_Type__c = NewItemType,
            Release_Date__c = NewItemReleaseDate);
        insert NewItem;    
    }
    
    DisplayMerchandise[] products;

    public class DisplayMerchandise {
        public Item__c merchandise { get; set; }
        public DisplayMerchandise(Item__c item) {
            this.merchandise = item;
        }
    }

    public DisplayMerchandise[] getProducts() {
        if (products == null) {
            products = new DisplayMerchandise[]{};
            for (Item__c item : 
                [SELECT id, name, item_price__c, createddate, item_type__c 
                 FROM Item__c ]) {
               products.add(new DisplayMerchandise(item));
             }
         }
     return products;      
    }
}

 There are two problems that i can't solve because of my inexperience:

1) How can i implement formatted input of ReleaseDate? It is desirable a calendar to be rendered when focus is on the corresponding inputText.

2) How can i clean all the inputText elements on my page when commandButton is down and new record is added successfully?

 

Thanks in advance.

Hello!

 

I did the following - copied and edited APEX class from tutorial so it looks like this:

 

public class FullFunctionality {

    DisplayMerchandise[] products;

    public class DisplayMerchandise {
        public Item__c merchandise { get; set; }
        public DisplayMerchandise(Item__c item) {
            this.merchandise = item;
        }
    }

    public DisplayMerchandise[] getProducts() {
        if (products == null) {
            products = new DisplayMerchandise[]{};
            for (Item__c item : 
                [SELECT id, name, item_price__c 
                 FROM Item__c ]) {
               products.add(new DisplayMerchandise(item));
             }
         }
     return products;      
    }
}

 My VF page uses this classlike this -

 

<apex:page standardStylesheets="false" showHeader="false" sidebar="false" Controller="FullFunctionality">
<apex:stylesheet value="{!URLFOR($Resource.Styles, 'styles.css')}"/>

<apex:dataTable value="{!products}" var="pitem" rowClasses="odd,even" align="center">
    <apex:column >
        <apex:form style="width:50px">
            <apex:inputCheckbox />
        </apex:form>
    </apex:column>
    <apex:column headerValue="Item name" style="text-align:left">
        <apex:outputText value="{!pitem.name}"/>
    </apex:column>
    <apex:column headerValue="Price" >
        <apex:outputText value="{!pitem.Item_Price__c}"/>
    </apex:column>

</apex:dataTable>
</apex:page>

 But I get an error message:"Error: Unknown property 'FullFunctionality.DisplayMerchandise.name'"

 

Please help me to get rid of it.

Thanx in advance.

I wonder if i have an opportunity to do such thing.

My custom object in my app is called "Item". There is a tab on the top of the page called "Items". How can i make VF page to be shown instead of standard salesforce interface when i click this tab?

Can a validation rule function as a conttroller on a VF page?

 

I made a very simple validation rule and want now to see a VF page, that is already done too. As far as i understood validation rule should be its controller, but i can't find out how to do it exactly.

 

 http://www.salesforce.com/us/developer/docs/pages/index.htm - i've found this, but it is not my case, because i want to be thrown to my VF page when validation rule fires, otherwise i want to see interface by default.

 

Can you help me?

Hello!

Don't judge me harshly - i'm newbie =).

For some hours i can't get over the error - "Expression cannot be assigned at line -1 column -1".

It appears every time i try to save the following APEX trigger -

 

trigger ItemAvailabilityChange on Item__c (before update) {

    if (Item__c.Items_Available__c == 0)
        Item__c.Availability__c = false;
    else 
        Item__c.Availability__c = true;
}

 Thanks in advance.

Hi to everyone out there!

 

I've got an issue with turning Chatter off. There are such declarations in my controller in test method:

 

CollaborationGroup CgTest1 = new CollaborationGroup(Name = 'CgTest1', CollaborationType = 'Public');
		insert CgTest1;
		
		CollaborationGroup CgTest2 = new CollaborationGroup(Name = 'CgTest2', CollaborationType = 'Public');
		insert CgTest2;
		
		CollaborationGroupMember CgmTest1 = new CollaborationGroupMember(CollaborationGroupId = CgTest1.Id, MemberId = u.Id);
		insert CgmTest1;

 So when i'm trying to turn Chatter off the message being received - 

Cannot disable Chatter. It is referenced by the following components: 

I tried to put these declarations in try catch block - no results. I tried to make declarations only when 

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
if(gd.containsKey('FeedItem'))

gd.containsKey('FeedItem') == true - still the same message.

 

Is there any workaround for such issue?

 

Thanks in advance.

Greetings to everyone!

Here is a question. My APEX controller:

 

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   private String searchStr = ' order by ';
   public Date searchDateCopy;
   public String searchTextCopy;
   public Boolean EndSearch { get; set; }
   public Boolean DelCopy { get; set; }
   public Boolean MakeCopy { get; set; }
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }
   public String searchText {get;set;}
   public Date searchDate { get; set; }
   public List<Item__c> searchResults {get;set;}
   
   public fullfunctionality_2() {

       ViewData();
   }

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate
                );
                insert NewItem; 
                ViewData();
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                NewItemName=null;
                NewItemQuantity=null;
                NewItemPrice = null;
                NewItemReleaseDate = null;
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;   
               
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();     
        return curPage;          
    }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
       if (DelCopy == true){
           searchDateCopy = null;
           searchTextCopy = null;}

       if (MakeCopy == true) {
           searchDateCopy = searchDate;
           searchTextCopy = searchText;
       }    
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       if(searchTextCopy != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchTextCopy + '%\' order by ';}
       if(searchDateCopy != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchTextCopy + '%\' and DAY_ONLY(CreatedDate) =:searchdatecopy order by ';}   
           
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c ' + searchstr + sortFullExp);
       

           searchText = null;
           searchDate = null;

       return null;
   }
}

 And here is a test class for controller:

 

@isTest
private class TestFullFunctionality_2 {

String NewItemName = 'NEWITEM';
Integer NewItemPrice = 100;
String NewItemType = 'Solid';
Integer NewItemQuantity = 10;

static testMethod void testAdd() {
TestFullFunctionality_2 ext;       
Item__c NewItem = new Item__c(name = 'NEWITEM', Item_Price__c = 100, Item_Type__c = 'Solid', Items_Available__c = 10 );
insert NewItem;
FullFunctionality_2 Con=new FullFunctionality_2();
Con.add();
Con.del();
Con.viewData();

}
}

 I still cannot understand - why do i get an error:

 

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Item_Price__c]: [Item_Price__c]

 Maybe someone can help me?

 

Thanks in advance.

Greetings to everybody out there!

So here is the question. There is a SOQL query that being formed like this:

       date mysearchdate=date.valueOf(searchDate);
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       if(searchText != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchText + '%\' order by ';}
       if(searchDate != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchText + '%\' and CreatedDate >=: mysearchdate order by ';}   
           
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c ' + searchstr + sortFullExp);

 Well, the main problem is in this -

CreatedDate >=: mysearchdate

part of code. It doesn't work when i need to perform accurate comparison:

CreatedDate =: mysearchdate

Why?

 

Thanks in advance.

Greetings to everyone!

 

I've got a problem that had most of you, i think =)

There is an inputtext on my VF page:

<apex:inputText value="{!NewItemReleaseDate}" id="rdate" label="Release Date" onfocus="DatePicker.pickDate(false, this, false);"/> 

 As you can see users enter date here.

Also there is a PageBlockSection that function as a search block:

        <apex:pageBlockSection title="Search an item by name and\or release date" collapsible="false">      
        <apex:pageBlockSectionItem >
        <apex:panelGrid >
          <apex:outputLabel style="float:left">Name</apex:outputLabel>
              <apex:inputText id="searchText" value="{!searchText}" style="float:left"/>
          <apex:outputLabel style="float:left" >Date</apex:outputLabel>  
          <apex:inputText id="searchDate" value="{!searchDate}" onfocus="DatePicker.pickDate(false, this, false);" style="float:left">
              <apex:param value="{0,date,MM/dd/yyyy}" assignTo="{!searchDate}"/>    
          </apex:inputText>          
          <apex:commandButton id="SearchButton" value="Search" action="{!ViewData}" reRender="FullFunctionalityForm">
              <apex:param value="WHERE name=" assignTo="{!searchStr}"/>
              <apex:param value="" assignTo="{!searchDate}"/>
          </apex:commandButton>
        </apex:panelGrid>
        </apex:pageBlockSectionItem>
      </apex:pageBlockSection>

 Here is a search method from my APEX controller:

   public PageReference ViewData() {
   
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       if(searchText != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchText + '%\' order by ';}
       if(searchDate != null) {
           searchstr = 'WHERE Name LIKE \'%' + searchText + '%\' and CreatedDate =: searchDate  order by ';}              
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c ' + searchstr + sortFullExp);

       return null;
   }

 ...and it doesn't work!!! =(

I guess that my issue concerns date formats both that entered when user adds new item and when searching one.

 

Help me please!

 

Thanks in advance.

Greetings to everyone!

 

Strictly speaking - my question is in subject. I have a PageBlockTable on a VF page:

 

<apex:pageBlockTable value="{!items}" var="i" id="ListOfItems" >

 Is it possible to change its "value" attribute to another one by clicking a button:

 

 <apex:commandButton value="Search" action="{!search}" rerender="resultsBlock" status="status"/>

 Thanks in advance.

Hi there!

There is a little problem with using DatePicker in inputText component on a VF page. I implement it like this:

 

    <apex:inputText value="{!NewItemReleaseDate}"  label="Release Date" onfocus="DatePicker.pickDate(false, this, false);" />

 Calendar appears and date is picked well but it doesn't appear in inputText. Why? I can't see the solution. May be you do?

 

Thanks in advance.

Greetings to everyone!

 

I've got a problem writing test for my Apex controller. Here is controller:

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }
   public string searchText {get;set;}
   public List<Item__c> searchResults {get;set;}

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate);
                insert NewItem; 
                ViewData();
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                NewItemName=null;
                NewItemQuantity=null;
                NewItemPrice = null;
                NewItemReleaseDate = null;
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;   
               
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();
        curPage.setRedirect(false);       
        return curPage;
            
    }    

  public PageReference search() {
        String qry = 'select id, name, createddate, item_price__c from Item__c ' +
        'where name LIKE \'%'+searchText+'%\' order by name';
        searchResults = Database.query(qry);
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        ViewData();
        curPage.setRedirect(true);       
        return null;        
  }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
   
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c order by ' + sortFullExp + ' limit 1000');
       return null;
   }
}

 I wrote a piece of test, it looks like this:

 

@isTest
private class TestFullFunctionality_2 {

static testMethod void testItemEnter() {

    Item__c NewItem = new Item__c(name = 'NEWITEM', Item_Price__c = 100, Item_Type__c = 'Solid', Items_Available__c = 10 );
    insert NewItem;
    Test.startTest();
    Test.stopTest();    
}
}

 ...but still the code coverage total is 0%. What do i do wrong?

 

Thanks in advance.

Greetings to everyone!

 

Look, here is my VF page:

<apex:page standardStylesheets="false" showHeader="false" sidebar="false" controller="Fullfunctionality_2">
<apex:stylesheet value="{!URLFOR($Resource.Styles, 'styles.css')}"/>
<apex:sectionHeader title="List of items in stock with ADD, DELETE, SORT and SEARCH functions"></apex:sectionHeader>
<apex:form >
<apex:pageBlock >
      <apex:commandButton value="Show items" action="{!ViewData}" >
      </apex:commandButton> 
    <apex:pageBlockTable value="{!items}" var="i" >
    <apex:column >
        <apex:commandLink action="{!del}" value="Delete">
            <apex:param name="idtodel" value="{!i.id}" assignTo="{!IDToDel}"/>
        </apex:commandLink>
    </apex:column>
       <apex:column style="text-align:left">
         <apex:facet name="header">   
           <apex:commandLink action="{!ViewData}" value="Item name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
             <apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputText value="{!i.name}"></apex:outputText>
       </apex:column>
       <apex:column style="text-align:left">
           <apex:facet name="header">
               <apex:commandLink action="{!ViewData}" value="Price{!IF(sortExpression=='Item_Price__c',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
                   <apex:param value="Item_Price__c" name="column" assignTo="{!sortExpression}"/>
               </apex:commandLink>
           </apex:facet>
           <apex:outputText value="{!i.Item_Price__c}"/>
       </apex:column>
       <apex:column >
           <apex:facet name="header">
               <apex:commandLink action="{!ViewData}" value="Adding date{!IF(sortExpression=='createddate',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
                   <apex:param value="createddate" name="column" assignTo="{!sortExpression}"/>
               </apex:commandLink>
           </apex:facet>
           <apex:outputText value="{0,date,MM/dd/yyyy}">
               <apex:param value="{!i.createddate}"/>
           </apex:outputText>
       </apex:column>
    </apex:pageBlockTable>
    <apex:pageBlockSection columns="1">
    <apex:inputText value="{!NewItemName}" label="Name" style="text-align:left"/>
    <apex:selectList id="types" size="1" required="true" label="Type" >
        <apex:selectOptions value="{!types}"/>
    </apex:selectList>
    <apex:inputText value="{!NewItemPrice}" label="Price" style="text-align:left" />
    <apex:inputText value="{!NewItemQuantity}" label="Quantity" style="text-align:left"/>
    <apex:inputText value="{!NewItemReleaseDate}"  label="Release Date"/>
    <apex:commandButton value="Add item" action="{!add}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 And its APEX controller:

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate);
                insert NewItem; 
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;                     
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        curPage.setRedirect(true);
        return curPage;
            
    }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
   
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c order by ' + sortFullExp + ' limit 1000');
       return null;
   }
}

 I have some questions.

1) As you can see there are such elements like pageBlockTable and pageBlockSection. When VF page is being rendered pageBlockSection is situated below pageBlockTable. And I want it to be situated to the right to pageBlockTable. How can i do it?

2) When i add or delete an item the page reloads and i see only header of pageBlockTable. The same occurs when i load page for the first time during the session. How can i avoid it?

 

Thanks in advance.

Greetings to everyone!

 

On my VF i have a commandlink and it looks like this:

        <apex:commandLink value="Delete" action="{!del}">
            <apex:param name="idtodel" value={!pitem.merchandise.id}"/>
        </apex:commandLink>

 In my Apex controller i want to implement deletion like this:

    public PageReference del() {
    Id IdToDel=System.currentPageReference().getParameters().get('id');
    Item__c ItemToDel = [SELECT all
                         FROM Item__c
                         WHERE id = IdToDel];
    PageReference curPage = ApexPages.currentPage(); 
    curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        curPage.setRedirect(true);
        return curPage; 
            
    }

and i get an error "unexpected token: 'IdToDel' at line 7 column 40"