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
NakataNakata 

How to direct to custom object detail page ?

Good day, 

 

I trying to redirect to a custom object(myObject) page when user click on the button from custom VF page, MyObject detail page having required fields which have set in page layout. what i need is do not manual set the required field value and insert myObject into DB before redirect, anyone have idea how can i fulfill this requirement ?

 

the whole purpose and intention is:

in pageA , when user click a button, it bring user to MyObject detail page and some preset value from pageA will carry and fill into MyObject detail page.

 

Thank you !

 

 

public PageReference doSelectContact(){
		
String contactId = ApexPages.currentPage().getParameters().get('selectedContactId');

if(StringUtils.isNotBlank(contactId)){
			myObject= new myObject(); 
		}
//insert myObject;
PageReference myObjectPage= new ApexPages.StandardController(myObject).view();		

 

 

myObjectPage.setRedirect(true);
return myObjectPage;
}

 

 

SPrashantSPrashant

 try to emitatethe URL which populate the field values in your details page on redirect.

 

Then pass that URL using Pagereference in your VisualForce Page.

 

 

 

 

forecast_is_cloudyforecast_is_cloudy

See this email thread on how you can pre-populate some fields on a new record page (which is what I believe you're trying to do) - http://boards.developerforce.com/t5/Product-Discussion/Help-with-WIL/td-p/5882

samarsamar

Hi Nakata,

I am pretty sure you are using the same controller where you are writing the doSelectContact() method behind the custom vf page where you have the link to navigate to the detail page of the object. If it so then use the default getter setter method of the varibles you need to insert. when you click the link, the page ll be posted and ll call the default setter method. Then set the values to the corresponding fields of the object from the varibles used in the vf page and insert the record. Then redirect the page to the detail page of the recently created record.

NakataNakata

Thanks All for the help, i used WIL and get solved !

 

the code sample like below, that's prompt me another question, how can we get the URL "/a0v/e" dynamically in different environment ? i wish not to hardcode it ...

 

 

public PageReference doSelectContact(){
		
String contactName = ApexPages.currentPage().getParameters().get('mycontactName');		
		
		
String urlStr = '/a0v/e' + '?CF00NT0000001Km7f=' + contactName +'&CF00NT0000001KlqU=' + accountName ;
		
PageReference MyObjectPR= new 
PageReference(urlStr);
		
return MyObjectPR;
	}

 

 

 

samarsamar

Hi Nakata,

Use the following code to dynamically create the URL

 

 

Schema.Describesobjectresult result = Schema.Sobjecttype.YourCustomObjName;
String prefix = result.getKeyPrefix();
String urlStr = '/'+prefix+'/e'  + '?CF00NT0000001Km7f=' + contactName +'&CF00NT0000001KlqU=' + accountName ;

 Hope this will help you.

 

 

Thanks,

Samar

NakataNakata

Many thanks Samar for the enlightenment !

 

what about field id like '

CF00NT0000001Km7f

'

can we get it dynamically as well ?