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
DTRain521DTRain521 

Redirect button from VF page

Hi, I have a need for a button from a VF page to rediert me to the landing page for record type selection for creating a new record on a custom object. Custom object has a master detail relationship with Opportunity. I have created the button but need help with the APEX coding in the class for the VF page. Any help would be greatful. Thanks Dwayne
b-Forceb-Force

create a apex CommandButton on page give a action function

 

on controller  side

 

 

PageReference pageRef = new PageReference('https://cs3.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IQ0000000D12q
');
pageRef.setRedirect(true);
return pageRef;

 

 

replace 01IQ0000000D12q by your custom object Id  to get Object Id go to setup----> your custom object ----> you can get Id in url  also Change your Salesforce instance accordingly

 

 

as you explained your custom object has Master-Detail with opportunity,

if you want this Opportunity should select autometically after record selection page

then need some more input from your side

like

 

1) VF page from where you are redirecting, Are you showing opportunity on this page [So we can get ID and Name of Opportunity]

2)What is recordId of your Master Detail field on custom object

3) What is object prefix of your custom object

 

if you want simple recordtype selection page then first solution is enough, else give these detail 

 

Hope this will help you

 

Thanks,

Bala

DTRain521DTRain521
Yes the VF page that I am on does have the ID of the opportunity. It will need to pass along but should be easy to identify as policy.id, policy being designated as the current record.
b-Forceb-Force

So you need to go with Second option,

Could you please provide , other three factors, so we can create link that will populate current Opportunity in edit Layout  of your custom object.

 

you can get this information easily by using apex Explorer or Eclipse

 

 

Thanks,

Bala

DTRain521DTRain521
I believe that you are looking for the field that represents the opportunity on the custom object? if so it is as follows: Service_Notifications__c as custom object and Opportunity__c as the master detail field.
b-Forceb-Force

Basically we want to generate Correct pagereference URL which will hit RecordType selection Page ,

After selecting record type, It will return to Service_Notifications__c  edit page.

 

to generate correct URL do following Exercise (****** Just to get correct URL parameter and Formats )

1) Add  Service_Notifications__c related List on Opportunity page Layouts with (New button)

2) Click on New Service_Notifications__c button from related list ,

3) RecordType selection Page will appear  ... this is the URL you need to generate,

which looks like

 

https://cs3.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IQ0000000D12q&retURL=/001Q000000FC97v&save_new_url=/a1z/e%3FCF00NQ0000000iKS1%3DReseller%2BAccount%2B1%26CF00NQ0000000iKS1_lkid%3D001Q000000FC97v%26retURL%3D%252F001Q000000FC97v

 from this url you need to just replace current Opportunity record Id  and Opportunity Name

In above example  Id was 001Q000000FC97v  and Name was Reseller Account

 

 

Hope this will help you,

 

Thanks,

Bala

 

 

 

 

Jack InsJack Ins
Sorry to be a pain but it still did not redirect to the service notification page just the landing page to select the record type.  It will not let me continue from there.
I have pasted the code below.
Here is the url from the opp page to the landing service notification page.
https://tapp0.salesforce.com/setup/ui/recordtypeselect.jsp?retURL=%2F0064000000EkBjTAAV&ent=01IT000000058Gq&ent=01IT000000058Gq&RecordType=012T0000000D3Ru
public PageReference ServiceNotifications()
    {
    PageReference pageRef = new PageReference('https://tapp0.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IT000000058Gq&retURL=' + policy.Id);
    pageRef.setRedirect(true);
    return pageRef;
    }

 

b-Forceb-Force

your page reference URL is incorrect 

It contains only retUrl Parameter (Even this parameter is not holding any value in your case ) 

 

your URL should be something like 

https://cs3.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IQ0000000D12q&retURL=/001Q000000FC97v&save_new_url=/a1z/e%3FCF00NQ0000000iKS1%3DReseller%2BAccount%2B1%26CF00NQ0000000iKS1_lkid%3D001Q000000FC97v%26retURL%3D%252F001Q000000FC97v

 

save_new_url  this parameter is missing from your code 

 

 

if above things will not help you, let me check the code from your code, if you think so :) drop me mail 

 

Also try the exercise that I have explained previously 

 

Thanks,

Bala

 

 

 


Jack InsJack Ins

Bala,

Thanks for your help on this.  I am still having trouble and dont quite understand.  Here is my code for the redirect, I think I may just be coding the url string wrong.

 

public PageReference ServiceNotifications()
    {
    	PageReference pageRef = new PageReference('https://tapp0.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IT000000058Gq&retURL=/' + policy.Id + '&save_new_url=/' + policy.name );
    	pageRef.setRedirect(true);
    	return pageRef;
    }

 

b-Forceb-Force

Jack, 

 

you are constructing save_new_url in some incorrect way .

your save_new_url must like contains /Service_Notification_Object_Prefix/e 

so this will open new edit page with Service_Notification_Object edit layout 

 

Thanks,

Bala

Jack InsJack Ins

Bala,

I dont understand what you mean.  Where would I place the "/Service_Notification_Object_Prefix/e"

 

b-Forceb-Force

Is it possible to access your dev Org for me , I will do it for you (if you want so )

I have a sent a mail to you previously. 

 

Thanks,

Bala

Jack InsJack Ins

I have this in my sandbox and there is sensitive data that can not be shared.  Sorry

 

Is there any thing that I can post here.  I had posted the actual url at one point if that helps.

b-Forceb-Force

no problem .......

 

do this exercise  

 

to generate correct URL do following Exercise (****** Just to get correct URL parameter and Formats )

1) Add  Service_Notifications__c related List on Opportunity page Layouts with (New button)

2) Click on New Service_Notifications__c button from related list ,

3) RecordType selection Page will appear  ... this is the URL you need to generate,

 

copy the resultant URL from browser address Bar and Post here,

 

If you have any issue for this exercise get back to me

 

 Thanks ,

Bala  

b-Forceb-Force

Also post your code of apex controlller 

 

Thanks,

Bala

b-Forceb-Force

 

public PageReference ServiceNotifications()
    {
    PageReference pageRef = new PageReference('https://tapp0.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IT000000058Gq&retURL=/'+policy.Id+'&save_new_url=/a0s/e%3FCF00NT0000001GcgE'+policy.name +'26CF00NT0000001GcgE_lkid%3D0064000000EkBjT%26retURL%3D%252F'+policy.id);
    pageRef.setRedirect(true);
    return pageRef;
    }

 try with above code once 

 

Let me know 

 

 Thanks ,

Bala

 

b-Forceb-Force

hey could you please send me Email id , 

so I can mail you updated controller code 

 

I m trying to put source code here ..............but here Html formating adding some unwanted characters  in code like '+......'

you can see.

 

Will send updated code as attachement

 

Thanks,

Bala

 

 

 

Jack InsJack Ins

Visualforce Error


System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Name

 

Class.PolicyDashboardController.ServiceNotifications: line 270, column 171 External entry point

 


 

<script type="text/javascript"></script>
Jack InsJack Ins

Visualforce Error


System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Name

 

Class.PolicyDashboardController.ServiceNotifications: line 270, column 171 External entry point

b-Forceb-Force

add Name field where you have made query while retriving Opportunity record

 

like [Select Id, Name ,........ from Opportunity where .......]

 

 

Thanks,

Bala

b-Forceb-Force

Any updates ?

 

Jack InsJack Ins

Yes I have this it would be policy.name

b-Forceb-Force

Does new Page Reference URL works for you ?

 

Thanks,

Bala

Jack InsJack Ins

Bala,

Just noticed a response from you that I missed.

 

My email address is dtrain521@gmail.com

 

Thanks Dwayne

Jack InsJack Ins

Any News?

b-Forceb-Force

updated script sent at your email id ,

 

Thanks,

Bala

Jack InsJack Ins

I get the following error:

 

URL No Longer Exists
You have attempted to reach a URL that no longer exists on salesforce.com.

You may have reached this page after clicking on a direct link into the application. This direct link might be:
• A bookmark to a particular page, such as a report or view
• A link to a particular page in the Custom Links section of your Home Tab, or a Custom Link
• A link to a particular page in your email templates

If you reached this page through a bookmark, you are probably trying to access something that has moved. Please update your bookmark.

If you reached this page through any of the other direct links listed above, please notify your administrator to update the link.

If you reached this page through a link on our site, please report the broken link directly to our Support Team and we will fix it promptly. Please indicate the page you were on when you clicked the link as well as any other related information. We apologize for the inconvenience.

Thank you again for your patience and assistance. And thanks for using salesforce.com!
b-Forceb-Force

you need to encode the URL,

 

Mainly, If your policy.name contains some space (should get replaced by ENCODE character )

 

check is there any way so we can encode this fields and formed correct URL,

 

Also mail me URL in browser when you get this error message [in some Text file ] or ping me on gtalk 

 

Thanks,

Bala