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
abi dzarabi dzar 

Show Specific Record in Visual Force without passing Id in URL

I'm trying to make a Custom Visual Force page that will specifically open a fixed case without passing the Case Id in the URL.

 

Can I do that?

 

Kind Regards,

Abi Dzar

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

So you want to stay on your custom visualforce page but allow the user to edit some values?

 

In that case, you need to pull all the values that can be changed as part of the constructor SOQL call. Remove the page level action, as you want to leave the user where they are.  Then in your page, simply use apex:inputField components to display the existing values and allow the user to edit them.  Finally, you'll need a save action method to apply the changes to the database.

All Answers

bob_buzzardbob_buzzard

If you don't pass the case id on the URL, you will need some way to determine which case should be opened.  Do you have some rules for this?  

abi dzarabi dzar

Thanks for the reply bob_b.

 

How do we set that?

The only rule is to make query check weather is there a case with specific email or not. 

 

Then show in VF.

I tried something. by using action function in <apex:page> but it redirect me to default editing. 

I want it to be viewed inside the page. 

 

regards, 

Abi Dzar

 

bob_buzzardbob_buzzard

In that case you need a controller that will carry out the SOQL to locate the case in question.  

abi dzarabi dzar

This is my code

 

in Controller
public editCase(ApexPages.StandardController controller) {
this.mycase = [SELECT id FROM Case WHERE email = :'someemail' limit 1];    
}


public PageReference redirectToObject(){
PageReference my = new ApexPages.StandardController (mycase).edit();
return my.setRedirect(false);
        
}

in VF,

<apex:page standardController="my_case__c" extensions="CaseController" 
showHeader="false"  action="{!redirectToObject}">
     <apex:detail relatedList="false" title="true"/>  
</apex:page>

 

Hope this will help

 

abi dzarabi dzar

 

in Controller
public CaseController(ApexPages.StandardController controller) {
this.mycase = [SELECT id FROM Case WHERE email = :'someemail' limit 1];    
}


public PageReference redirectToObject(){
PageReference my = new ApexPages.StandardController (mycase).edit();
return my.setRedirect(false);
        
}

in VF,

<apex:page standardController="Case" extensions="CaseController" 
showHeader="false"  action="{!redirectToObject}">
     <apex:detail relatedList="false" title="true"/>  
</apex:page>

 I'm sorry, there is some mistake in the pasted code. I hope this is better.

 

bob_buzzardbob_buzzard

So do you want to display the information in your current page?

 

If so, you shouldn't return a page reference to a different page.  Rather you should use the mycase property to back the output fields etc that you have in this page.

 

Or am I misunderstanding what you are trying to do?

abi dzarabi dzar

Yes, that what I want to do.

But, How do I do that?

 

When You mention "output fields", means, the data can still be modified rite?

How do I do that? 

 

Thanks.

bob_buzzardbob_buzzard

So you want to stay on your custom visualforce page but allow the user to edit some values?

 

In that case, you need to pull all the values that can be changed as part of the constructor SOQL call. Remove the page level action, as you want to leave the user where they are.  Then in your page, simply use apex:inputField components to display the existing values and allow the user to edit them.  Finally, you'll need a save action method to apply the changes to the database.

This was selected as the best answer
abi dzarabi dzar

Bob, I got the idea. 

The only problem is I dunno how to stay at my own custom VF. 

and let user edit the data from that VF. 

bob_buzzardbob_buzzard

Just remove your page level action.  There's no need to try to send the user off anywhere else, just leave them where they are. 

abi dzarabi dzar

Thanks Bob, 

 

I tried to access using inputfield and remove the page level action.

Then its all done. :)

 

Thanks a lot.