function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amruta_dhumalamruta_dhumal 

Pass parameter to edit layout thru Vf page

Hi

 

I want to redirect vf page values to particular object's edit layout fields. and on edit layout user should not be able to edit/change any of the fields which are auto-populate from vf page.

 

How I can restrict user for this..is it possible?any help would be appreciated...

 

Amruta

 

I developed this code:

 

VF page:

<apex:page standardController="Contact" extensions="ContactSearchController1" showHeader="false">
 
 <script>var cId = "{!Contact.Id}";</script>
   <apex:form >
  <apex:pageMessages id="errors" />
 
  <apex:pageBlock title="Find A Pre-Wired Site Address!" mode="edit">
 
  <table width="100%" border="0">
  <tr> 
    <td width="300" valign="top">
 
      <apex:pageBlock title="Parameters" mode="edit" id="criteria">
 
      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("firstName").value,
          document.getElementById("lastName").value,
          document.getElementById("accountName").value,
          document.getElementById("technology").options[document.getElementById("technology").selectedIndex].value
          );
      }
      </script>
 
      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="firstName" value="" />
          <apex:param name="lastName" value="" />
          <apex:param name="accountName" value="" />
          <apex:param name="technology" value="" />
      </apex:actionFunction>
 
      <table cellpadding="2" cellspacing="2">
      <tr>
        <td style="font-weight:bold;">First Name<br/>
        <input type="text" id="firstName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Last Name<br/>
        <input type="text" id="lastName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;"><font color ="red">Account</font><br/>
        <input type="text" id="accountName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Interested Technologies<br/>
          <select id="technology" onchange="doSearch();">
            <option value=""></option>
            <apex:repeat value="{!technologies}" var="tech">
              <option value="{!tech}">{!tech}</option>
            </apex:repeat>
          </select>
        </td>
      </tr>
      </table>
 
      </apex:pageBlock>
 
    </td>
    <td valign="top">
 
    <apex:pageBlock mode="edit" id="results">
 
        <apex:pageBlockTable value="{!contacts}" var="contact">
 
        <apex:column headerValue="Action">
        <apex:commandLink action="{!next}"> Select</apex:commandLink>


       <!-- <apex:outputLink value="/apex/openlookup?firstName={!contact.firstName}&lastName={!contact.lastName}&account.name={!contact.account.name}&interested_technologies__c={!contact.Interested_technologies__c}" target="_blank" id="one">Select</apex:outputLink>-->
         </apex:column>
        <apex:outputField label="FirstName" value="{!contact.firstName}"/>
                   <apex:column >             
             <apex:facet name="header">
             

                   <apex:commandLink value="First Name" action="{!toggleSort}" rerender="results,debug">&nbsp;&nbsp;&nbsp;&nbsp;
               

                                       <apex:param name="sortField" value="firstName" assignTo="{!sortField}"/>
                   </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.firstName}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Last Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="lastName" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.lastName}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Account" action="{!toggleSort}" rerender="results,debug">
                                            <apex:param name="sortField" value="account.name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.account.name}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Technologies" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="interested_technologies__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.Interested_technologies__c}"/>
            </apex:column>
 
 
        </apex:pageBlockTable>
 
    </apex:pageBlock>
       </td>
  </tr>
    <apex:pageBlock title="Not Found Any Matching Records">
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <apex:commandLink value="Next" action="{!next}"/>
  </apex:pageBlock>
  </table>
    
  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />          
  </apex:pageBlock>   
 
  </apex:pageBlock>
 
  </apex:form>
 
</apex:page>

 

++++++++++++++++++++++++++++

 

Controller class:

 

public with sharing class ContactSearchController1 {
    public ContactSearchController1(ApexPages.StandardController controller) {
    }

PageReference pageRef ;

 
 
  private String soql {get;set;}
 
  public List<Contact> contacts {get;set;}
   // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
 
  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'lastName'; } return sortField;  }
    set;
  }
 
  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }
 
  // init the controller and display some sample data when the page loads
  public ContactSearchController1() {
    soql = 'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null';
    runQuery();
  }
 
  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }
 
  // runs the actual query
  public void runQuery() {
 
    try {
      contacts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }
 
  }
 
  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
 String firstName = Apexpages.currentPage().getParameters().get('firstname');
    String lastName = Apexpages.currentPage().getParameters().get('lastname');
    String accountName = Apexpages.currentPage().getParameters().get('accountName');
    String technology = Apexpages.currentPage().getParameters().get('technology');

    
    soql = 'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null';
    if (!firstName.equals(''))
      soql += ' and firstname LIKE \''+String.escapeSingleQuotes(firstName)+'%\'';
    if (!lastName.equals(''))
      soql += ' and lastname LIKE \''+String.escapeSingleQuotes(lastName)+'%\'';
    if (!accountName.equals(''))
      soql += ' and account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\''; 
    if (!technology.equals(''))
      soql += ' and interested_technologies__c includes (\''+technology+'\')';
 
    // run the query again
    runQuery();
 
    return null;
  }
 
  // use apex describe to build the picklist values
  public List<String> technologies {
    get {
      if (technologies == null) {
 
        technologies = new List<String>();
        Schema.DescribeFieldResult field = Contact.interested_technologies__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
          technologies.add(f.getLabel());
 
      }
      return technologies;         
    }
    set;
  }
 
 public PageReference Next(){
   
     
   pageRef = new PageReference('/003/e?');
    PageRef.setRedirect(true);
       PageRef.getParameters().put('nooverride', '1');
    
 

Return PageRef;
  }

 
}