You need to sign in to do that
Don't have an account?
hareeshn
how to pass record id vf page to controler
Hi am tryong to share one job object record to one user using apex
Job__c is object in that name is one text field User is one object
am passing record id to command link but its not working please help on this:
i tryed using pageblock table and datatable but user id un able to pass to controler or takeing first values from select list takeing as default values
vf page
----------------------------------------------------------------------------
<apex:page standardController="Job__c" extensions="Jobformation1usercon">
<apex:form >
<apex:selectList size="1" value="{!jobst }" multiselect="false">
<apex:actionSupport event="onchange" reRender="table,opt" />
<apex:selectOptions value="{!Job}"> </apex:selectOptions>
</apex:selectList>
<apex:outputText id="opt" value="{!jobst }"></apex:outputText>
<apex:selectList size="1" value="{!selectedVal}" multiselect="false">
<apex:actionSupport event="onchange" reRender="table,opt1" />
<apex:selectOptions value="{!Value}">
</apex:selectOptions>
</apex:selectList>
<apex:outputText id="opt1" value="{!selectedVal}"></apex:outputText>
<apex:commandLink action="{!manualShareRead}" value="Share" id="table">
<apex:param name="id" value="{!Job__c.id}"/>
</apex:commandLink>
</apex:form>
</apex:page>
-------------------------------------------------------------------------------------------
apex page
---------------------------------------------------
public class Jobformation1usercon
{
List<user> con1= new List<user>();
public job__c j {get;set;}
Public List<string> usertselect{get;set;}
public string jobst { get;set;}
public user gp {get;set;}
public boolean nojb{get;set;}
public String selectedVal{get;set;}
public List<job__C> joblist {get;set;}
public Jobformation1usercon(ApexPages.StandardController controller)
{
Id id = System.currentPageReference().getParameters().get('id');
}
public List<SelectOption> getJob()
{
List<SelectOption> option = new List<SelectOption>();
for(job__c j: [Select id,name From job__c])
{
option.add(new SelectOption(j.name,j.name));
system.debug('option value is '+option);
}
return option;
}
public List<SelectOption> getValue()
{
List<SelectOption> option = new List<SelectOption>();
for(user gp: [Select id,name From user ])
{
option.add(new SelectOption(gp.name,gp.name));
system.debug('option value is '+option);
}
return option;
}
public PageReference manualShareRead()
{
Id id = System.currentPageReference().getParameters().get('id');
system.debug('Id Value is'+id);
system.debug('aaaaaaaaaaaaaaaaaaaaaa'+selectedVal);
con1 = [select id from user where name=:selectedVal];
system.debug('PGList value is'+con1);
Job__Share jobShr = new Job__Share();
jobShr.ParentId = id;
jobShr.UserOrGroupId = con1[0].id;
jobShr.AccessLevel = 'Read';
jobShr.RowCause = Schema.Job__Share.RowCause.Manual;
Database.SaveResult sr = Database.insert(jobShr,false);
system.debug('sr value is'+sr);
if(sr.isSuccess())
{
system.debug('sr.isSuccess() value:'+sr.isSuccess());
system.debug('if sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
return nextpage;
}
else {
system.debug('inner else sr.isSuccess() block');
Database.Error err = sr.getErrors()[0];
if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION &&
err.getMessage().contains('AccessLevel')){
system.debug(' iner if sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
return nextpage;
}
else
{
system.debug('outer else sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
return nextpage;
}
}
}
}
Job__c is object in that name is one text field User is one object
am passing record id to command link but its not working please help on this:
i tryed using pageblock table and datatable but user id un able to pass to controler or takeing first values from select list takeing as default values
vf page
----------------------------------------------------------------------------
<apex:page standardController="Job__c" extensions="Jobformation1usercon">
<apex:form >
<apex:selectList size="1" value="{!jobst }" multiselect="false">
<apex:actionSupport event="onchange" reRender="table,opt" />
<apex:selectOptions value="{!Job}"> </apex:selectOptions>
</apex:selectList>
<apex:outputText id="opt" value="{!jobst }"></apex:outputText>
<apex:selectList size="1" value="{!selectedVal}" multiselect="false">
<apex:actionSupport event="onchange" reRender="table,opt1" />
<apex:selectOptions value="{!Value}">
</apex:selectOptions>
</apex:selectList>
<apex:outputText id="opt1" value="{!selectedVal}"></apex:outputText>
<apex:commandLink action="{!manualShareRead}" value="Share" id="table">
<apex:param name="id" value="{!Job__c.id}"/>
</apex:commandLink>
</apex:form>
</apex:page>
-------------------------------------------------------------------------------------------
apex page
---------------------------------------------------
public class Jobformation1usercon
{
List<user> con1= new List<user>();
public job__c j {get;set;}
Public List<string> usertselect{get;set;}
public string jobst { get;set;}
public user gp {get;set;}
public boolean nojb{get;set;}
public String selectedVal{get;set;}
public List<job__C> joblist {get;set;}
public Jobformation1usercon(ApexPages.StandardController controller)
{
Id id = System.currentPageReference().getParameters().get('id');
}
public List<SelectOption> getJob()
{
List<SelectOption> option = new List<SelectOption>();
for(job__c j: [Select id,name From job__c])
{
option.add(new SelectOption(j.name,j.name));
system.debug('option value is '+option);
}
return option;
}
public List<SelectOption> getValue()
{
List<SelectOption> option = new List<SelectOption>();
for(user gp: [Select id,name From user ])
{
option.add(new SelectOption(gp.name,gp.name));
system.debug('option value is '+option);
}
return option;
}
public PageReference manualShareRead()
{
Id id = System.currentPageReference().getParameters().get('id');
system.debug('Id Value is'+id);
system.debug('aaaaaaaaaaaaaaaaaaaaaa'+selectedVal);
con1 = [select id from user where name=:selectedVal];
system.debug('PGList value is'+con1);
Job__Share jobShr = new Job__Share();
jobShr.ParentId = id;
jobShr.UserOrGroupId = con1[0].id;
jobShr.AccessLevel = 'Read';
jobShr.RowCause = Schema.Job__Share.RowCause.Manual;
Database.SaveResult sr = Database.insert(jobShr,false);
system.debug('sr value is'+sr);
if(sr.isSuccess())
{
system.debug('sr.isSuccess() value:'+sr.isSuccess());
system.debug('if sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
return nextpage;
}
else {
system.debug('inner else sr.isSuccess() block');
Database.Error err = sr.getErrors()[0];
if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION &&
err.getMessage().contains('AccessLevel')){
system.debug(' iner if sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
return nextpage;
}
else
{
system.debug('outer else sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+id);
return nextpage;
}
}
}
}
System.currentPageReference().getParameters().get('id')
Or
Make use of Apex:param
Or
You could have an action method in the controller that returns a pagereference to the pdf page, and set the id into the parameters. E.g.
PageReference gotoPDF() { PageReference result=Page.MyPdfPage; result.getParameters().put(id, MyObject__c.id); result.setRedirect(true); return result; }
Or you could do something with the onclick event of the button:
<apex:commandButton value="Print" onClick="window.location='MyPdfPage?id={!MyObject__c.id}'; return false;" />
See more info in the links below,
http://www.mindfiresolutions.com/How-to-pass-ID-in-Visualforce-1578.php
https://developer.salesforce.com/forums/ForumsMain?id=906F000000098faIAA
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000965BIAQ
Regards,
Ashish
I am not entirely sure of the exact issue present here, however you can try once by giving some different param name in the following line and check if you are able to fetch the value in the controller:
<apex:param name="id" value="{!Job__c.id}"/>
Also, try to debug the code by removing the other code snippets and check if the problem persists.