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
Sivasankari MuthuSivasankari Muthu 

Reg:Page Reference

Hi all,
I have two visualforce page and one controller in my scenario,
First page I give two input industry and product,its given the result certain group of company picture in href link.If I click one image it gives some relevent detail about the company its like  https://www.salesforce.com/customers/.


VFP-1
<apex:page sidebar="false" showheader="false" controller="sfdctest" tabStyle="account">
<apex:form >
<apex:pageMessages id="pId"/>
    <apex:image url="{!imageURL}">
    </apex:image>
      <apex:pageBlock title="Select a Industry & Product" >
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <apex:selectList value="{!searchStr}" size="1"> 
                    <apex:selectOptions value="{!Industrynames}" />
          </apex:selectList>    
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <apex:selectList size="1" value="{!productName}">
            <apex:selectOptions value="{!items}"/>
    </apex:selectList> 
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <apex:outputPanel id="myRerender">

         <apex:commandButton value="Submit" action="{!soslDemo_method}"  ReRender="pgId,pId"  />
            </apex:outputPanel>

      </apex:pageBlock>
    
    <apex:pageBlock title="Customer details" id="pgId">
        
       <apex:repeat value="{!acc}" var="account">
     
             
<style>
    body {margin:50px;}
   
div.img {

    -webkit-align-items: baseline;
    align-items:baseline;
     margin: 10px;
    border: 1px solid #ccc;
    float: left;
    width: 220px;
   
    margin-bottom:25px;
    box:0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
}    
  div.img:hover {
    
    border: 1px solid #777;
   
}

div.img img {
    max-width:100%;
    width: 100%;
    height: 150px;
    
}

    
div.desc {
    font-family:"arial";
    background-color : lightgrey;
    padding: 10px 20px;
   
    height: 50px;
    text-align: justify;
}   
 
    
   </style>      
 <body>
     

<div class="img" >

    <apex:outputLink target="_blank" value="{!$Page.custrefdetail}" id="tst" >   <!--   custrefdetail it is my second vfp -->
            <apex:image value="{!account.photo__c}" height="150" width="200"   /> 
        

            
     </apex:outputLink> 
    <div class="desc"><h1>
    
        {!account.Name}
        </h1>
        <p>
        {!account.Description}
        </p>
        </div>
   
</div>
    
     </body>
        </apex:repeat>
    </apex:pageBlock>
</apex:form>
</apex:page>
 
VFP: 2
<apex:page sidebar="false" showHeader="false" controller="sfdctest" action="{!hello1}" >
<apex:form >
  <apex:pageBlock >
    <apex:repeat value="{!accprd}" var="accs">
      <p>
     {!accs.Detail__c}
        </p>   

   </apex:repeat>  
        </apex:pageBlock>
     </apex:form>
  
</apex:page>

Controller

Public with sharing class sfdctest{
 Public List<Account> acc{get;set;} 
 Public List<accproducts__c> accprd{get;set;}
     public ApexPages.StandardSetController setController { get; set;}    
 public String imageURL{get;set;}
 Public String searchStr{get;set;} 
 public string productName{get;set;}

  public Void hello1(){
    accprd = New List<accproducts__c>(); 
     accprd = [SELECT Detail__c from  accproducts__c where Product__r.name =:productName  and account__c in (select ID from Account where industry=:searchStr)];
System.debug(productName);
   }

public List<selectoption> getIndustrynames()
{           
    list<selectoption> options = new list<selectoption>();            
    Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();
    list<schema.picklistentry> values = fieldResult.getPickListValues(); 
     options.add(new SelectOption('select','Select Industry'));     
    for (Schema.PicklistEntry a : values) 
    {                  
        options.add(new SelectOption(a.getLabel(), a.getValue()));
    } 
  
    return options; 
}


public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('selectprd','Select Product')); 
    for(product2 c : [select ID, name  from product2  where ID IN( select Product__c from accproducts__c )]){
        options.add(new SelectOption(c.ID, c.name));
    }  
    return options;
}
    
 public  sfdctest()
  {
    acc = New List<Account>();
    imageURL='/servlet/servlet.FileDownload?file=';
    List< document > documentList=[select name from document where Name='logo'];
    if(documentList.size()>0)
    {
      imageURL=imageURL+documentList[0].id;
    }
  }
     
  Public void soslDemo_method(){
      System.debug(searchStr);
   if(searchStr.length() > 1 && searchStr != 'select'){
       acc = [SELECT Name,image__c,photo__c,Description,website from Account  where industry=:searchStr and Id in (select account__c from accproducts__c where Product__c = :productName )  ];
        System.debug('product');
       if(acc.size() == 0) {
           apexPages.addmessage(new apexpages.message(apexpages.severity.WARNING, 'Sorry, data not found'));
            return;
          }
       }

   else{
       acc = [SELECT Name,image__c,photo__c,Description,website from Account  where Id in (select account__c from accproducts__c )  ];
      
   }
  }
   }

 I try to display the hello1 method detail__c value  in my vfp2.


Thanks,
M. Sivasankari.
Michael DsozaMichael Dsoza
Hi,

Can you please clarify your quesion that what exactly you want ???

Thnx

 
Sivasankari MuthuSivasankari Muthu
Hi Michael Dsoza,
 My scenario is like  this link e.g: https://www.salesforce.com/customers .(please refer this link) then, If I click any one image link my vfp-1 redirect to another vfp, that second page display the details of company information.
I was linked one visualforce page to another vfp.,
vfp -1
<apex:outputLink target="_blank" value="{!$Page.custrefdetail}"  >   
 <apex:image value="{!account.photo__c}" height="150" width="200"   />


In my second visuaforce page i call the one method hello1
 
<apex:page sidebar="false" showHeader="false" controller="sfdctest" action="{!hello1}" >
<apex:form >
  <apex:pageBlock >
    <apex:repeat value="{!accprd}" var="accs">
        {!accs.Detail__c}   
   </apex:repeat> 
        </apex:pageBlock>
     </apex:form>


controller:
 
public Void hello1(){
    accprd = New List<accproducts__c>();
     accprd = [SELECT Detail__c from  accproducts__c where Product__r.name =:productName  andaccount__c in (select ID from Account where industry=:searchStr)];
System.debug(productName);
   }


above the query productName  and  searchStr input comming from vfp -1.
In vfp-2  I call an action hello1,but a controller not known the productName  & searchStr  values. it return the value as null.Any code clarification please refer my first post.If you knows please tell me..

Thanks,
M. Sivasankari
Michael DsozaMichael Dsoza
Hi Sivasankari,

As you are using _target that means on clicking, you are opening new window. Also, you are passing URL as "$Page.custrefdetail". If you are passing parameter in URL then get the parameter value in Controller Use - ApexPages.currentPage().getParameters().get('keyName');
And If you are not passing parameter then set the parameter to make it accessible on second page.
Hope it will help you.
Mark Resolved. If it solves your query.
Sivasankari MuthuSivasankari Muthu
Hi Michael Dsoza,

I tried below code,
 
public PageReference  hello1(){
       
      String  searchStr1= ApexPages.currentPage().getParameters().get('searchStr');
    String productName1 = ApexPages.currentPage().getParameters().get('productName');
   accprd = New List<accproducts__c>(); 
 	accprd = [SELECT Detail__c,Product__c from  accproducts__c where Product__c =:productName1  and account__c in (select ID from Account where industry=:searchStr1)];
	
      System.debug(productName1);
       System.debug(searchStr1);
    	PageReference pagr= new PageReference('/apex/custrefdetail');   
           pagr.setRedirect(true); 
     
        return pagr;
}

but the value shows as null..

Thanks,
Sivasankari.