• cory m
  • NEWBIE
  • 0 Points
  • Member since 2009

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

I'm trying to put a simple text search box on a VF page that, when submitted, will redirect the user to the CRM Content search page along with the search term.  I can "hack the URL" manually to accomplish this.  For example, if I put /sfc/#search?searchTerm=blah in my browser, it behaves correctly.  however, I can't seem to get a visualforce page to redirect similarly.

 

Here's my controller code:

 

public with sharing class SalesPlaybookHomeController {

	public String searchString {get;set;}
	
	private final String path = '/sfc/#search';
	
	public PageReference search() {
        String queryString = '';
       //build the query string
        if (searchString != null && searchString.length() > 0){
            queryString = 'searchTerm=' + EncodingUtil.urlEncode(searchString, 'UTF-8');
        }
        PageReference p = new PageReference(path + '?' + queryString);
        p.setRedirect(true);
        return p;
    }
}

 

 

When the code executes, it redirects to the content page, but the query string is not there, and so the searchTerm is not passed correctly.

 

Is there a different way to formulate the URL in order to effect a CRM Content search?  Other ideas?

 

Thanks in advance,
Cory

  • January 12, 2011
  • Like
  • 0

I have a custom ojbect (Internal_Request__c) for which I am building a custom "new record" page.  Following the typical pattern of first making the user select a Record Type, I created a simple "select record type" page that gives the user a list of record types.  After submitting that page, the user is directed to the full form page with the selected Record Type ID on the query string.   Ideally, based on the new feature in version 20.0, I would like that form to be aware of the record type so that the select lists are filtered accordingly.  I can't seem to get it work though.  The page loads but the default RecordType is selected, not the one that was passed on the querystring from the previous page.

 

The parameter name on the query string is "rType"

 

Here is my controller for the second page:

 

public with sharing class CreateIRFormController {
	
    public Internal_Request__c ir {get;set;}
    
    public String rType {get; set;}
    
    public CreateIRFormController() {
        rType = ApexPages.currentPage().getParameters().get('rType');
        ir = new Internal_Request__c(recordtypeid = (ID)rType, subject__c = 'test pre-pop');
    }

    public PageReference save() {
        insert ir;
        ApexPages.StandardController sc = new ApexPages.StandardController(ir);
        return sc.edit();
    }
}

 

 

And the associated VF page:

 

<apex:page controller="CreateIRFormController">
	<apex:form >
	    <apex:pageBlock >
	        <apex:pageBlockSection >
		        <apex:inputField value="{!ir.RecordType}" />
		        <apex:inputField value="{!ir.Type__c}"  />
		        <apex:inputField value="{!ir.Account__c}"  />
		        <apex:inputField value="{!ir.Opportunity__c}"  />
		        <apex:inputField value="{!ir.Issue_Date__c}"  />
		        <apex:inputField value="{!ir.Number_of_Copies__c}"  />
		        <apex:inputField value="{!ir.Request_Due_Date_Time__c}"  />
		        <apex:inputField value="{!ir.Subject__c}"  />
		        <apex:inputField value="{!ir.Description__c}"  />
	        </apex:pageBlockSection>
	        
	       <apex:pageBlockSection >
	            <apex:inputHidden value="{!rType}" />            
	            <apex:commandButton value="Create" action="{!save}" />
	        </apex:pageBlockSection>
	
	    </apex:pageBlock>    
	</apex:form>
</apex:page>

 Note: the subject__c is correctly pre-populated by the constructor, but the record type does not work.

 

 

I tried a second version of the controller constructor, but it results in the following error message (which doesn't really make sense to me):

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Record Type ID: value not of required type: [RecordType (Name:PS Data Center, Id:012Q00000004SJfIAM)]".

 

    public CreateIRFormController() {
        rType = ApexPages.currentPage().getParameters().get('rType');
        RecordType rt = [select id,name from RecordType where id = :rType];
        ir = new Internal_Request__c(recordtype = rt);
    }

 

 

This feels like a common thing people would want to do, so I'm hoping I'm just missing something.  Any help is appreciated.

 

-Cory

  • November 08, 2010
  • Like
  • 0

I'm trying to put a simple text search box on a VF page that, when submitted, will redirect the user to the CRM Content search page along with the search term.  I can "hack the URL" manually to accomplish this.  For example, if I put /sfc/#search?searchTerm=blah in my browser, it behaves correctly.  however, I can't seem to get a visualforce page to redirect similarly.

 

Here's my controller code:

 

public with sharing class SalesPlaybookHomeController {

	public String searchString {get;set;}
	
	private final String path = '/sfc/#search';
	
	public PageReference search() {
        String queryString = '';
       //build the query string
        if (searchString != null && searchString.length() > 0){
            queryString = 'searchTerm=' + EncodingUtil.urlEncode(searchString, 'UTF-8');
        }
        PageReference p = new PageReference(path + '?' + queryString);
        p.setRedirect(true);
        return p;
    }
}

 

 

When the code executes, it redirects to the content page, but the query string is not there, and so the searchTerm is not passed correctly.

 

Is there a different way to formulate the URL in order to effect a CRM Content search?  Other ideas?

 

Thanks in advance,
Cory

  • January 12, 2011
  • Like
  • 0

I have a custom ojbect (Internal_Request__c) for which I am building a custom "new record" page.  Following the typical pattern of first making the user select a Record Type, I created a simple "select record type" page that gives the user a list of record types.  After submitting that page, the user is directed to the full form page with the selected Record Type ID on the query string.   Ideally, based on the new feature in version 20.0, I would like that form to be aware of the record type so that the select lists are filtered accordingly.  I can't seem to get it work though.  The page loads but the default RecordType is selected, not the one that was passed on the querystring from the previous page.

 

The parameter name on the query string is "rType"

 

Here is my controller for the second page:

 

public with sharing class CreateIRFormController {
	
    public Internal_Request__c ir {get;set;}
    
    public String rType {get; set;}
    
    public CreateIRFormController() {
        rType = ApexPages.currentPage().getParameters().get('rType');
        ir = new Internal_Request__c(recordtypeid = (ID)rType, subject__c = 'test pre-pop');
    }

    public PageReference save() {
        insert ir;
        ApexPages.StandardController sc = new ApexPages.StandardController(ir);
        return sc.edit();
    }
}

 

 

And the associated VF page:

 

<apex:page controller="CreateIRFormController">
	<apex:form >
	    <apex:pageBlock >
	        <apex:pageBlockSection >
		        <apex:inputField value="{!ir.RecordType}" />
		        <apex:inputField value="{!ir.Type__c}"  />
		        <apex:inputField value="{!ir.Account__c}"  />
		        <apex:inputField value="{!ir.Opportunity__c}"  />
		        <apex:inputField value="{!ir.Issue_Date__c}"  />
		        <apex:inputField value="{!ir.Number_of_Copies__c}"  />
		        <apex:inputField value="{!ir.Request_Due_Date_Time__c}"  />
		        <apex:inputField value="{!ir.Subject__c}"  />
		        <apex:inputField value="{!ir.Description__c}"  />
	        </apex:pageBlockSection>
	        
	       <apex:pageBlockSection >
	            <apex:inputHidden value="{!rType}" />            
	            <apex:commandButton value="Create" action="{!save}" />
	        </apex:pageBlockSection>
	
	    </apex:pageBlock>    
	</apex:form>
</apex:page>

 Note: the subject__c is correctly pre-populated by the constructor, but the record type does not work.

 

 

I tried a second version of the controller constructor, but it results in the following error message (which doesn't really make sense to me):

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Record Type ID: value not of required type: [RecordType (Name:PS Data Center, Id:012Q00000004SJfIAM)]".

 

    public CreateIRFormController() {
        rType = ApexPages.currentPage().getParameters().get('rType');
        RecordType rt = [select id,name from RecordType where id = :rType];
        ir = new Internal_Request__c(recordtype = rt);
    }

 

 

This feels like a common thing people would want to do, so I'm hoping I'm just missing something.  Any help is appreciated.

 

-Cory

  • November 08, 2010
  • Like
  • 0

Hi,

 

I am used to java development where I can use a constants file which I load when the application wakes up, from which I read in values during runtime. These are any constants that a system admin can configure.. like the email addresses to which notifications should go to, retry counts, url end points etc. In a Java application you modify a constants file and restart the application. How do you provide such functionality in APEX?  

 

thanks,

Odie