0

Is it possible to redirect the user to a custom object creation page from a visualforce page? If so, how can I get the URL of this creation page? And what would I need to do in the code to pass an argument with it? (eg: a custom object id)

1 Answer 1

2

You'd need to create a pagerefence method on your controller, similar to this:

public PageReference customObjectPageReference() {
    Schema.DescribeSObjectResult R = YourCustomObject__c.SObjectType.getDescribe();
    PageReference pr = new PageReference('/' + R.getKeyPrefix() + '/e');
    pr.getParameters().put('Id,'theId');
    return pr;
}

This is taking into account that the key prefix might be different on different orgs.

Note that only a limited set of arguments can be passed this way without hardcoding field id's. There are some workarounds for this, depending on what arguments you need to pass.

6
  • Thats working, apparently. However, when I try to use this solution with a Standard User, it doesn't work. I have two record types for this object, and regular users may access only one of them (and should remain this way). When I used your solution, SF threw an error of insuficient privileges, even though the classes are allowed for this profile. Any thoughts? Commented Mar 30, 2015 at 11:46
  • Does the Standard User have 'Create' authorization on the custom object? And do you specify any parameters in the PageReference? Commented Mar 30, 2015 at 11:53
  • Nevermind! I had to allow the profile to access the vf page and the custom tab. lol Thanks! Now I do need to pass the ID to the creation page. Commented Mar 30, 2015 at 12:02
  • Which Id? Are you referring to an existing custom object record, or do you need e.g. a lookup filled with an Id? Commented Mar 30, 2015 at 12:06
  • I need to pass an existing record. Like a product id, and I already have that id. Just need to pass it to the object creation page that takes it. However, this page is not a custom page. It is the default object creation page from SF. Commented Mar 30, 2015 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .