0

I am trying to open a record in Edit mode when a record type is selected. I am using the following code Im doing some mistake but dont know what.

PageReference('/e?retURL='+Apexpages.currentPage().getParameters().get('retURL')+'&recordType='+RecordTypeId);

  • Where is the id of the record that you want to open in Edit mode? – AslamK Oct 13 '15 at 13:37
  • @AslamK I am trying to create a record. My issue is there is a controller which calls different VF page based on Record type. Now I have a new record type which should have standard Page layout. – Tamil Oct 13 '15 at 13:44
  • Even then you are not specifying which object you want to create. If for example it is a new Account then the pagereference should start of like /001/e. Similarly find the prefix of the object you want to create and accordingly modify the URL. – AslamK Oct 13 '15 at 13:47
3

You are not specifying in your URL which object you want to create the new Record for.

So assuming it is Account, it should be

PageReference('\001\e?retURL='+Apexpages.currentPage().getParameters().get('retURL')+'&recordType='+RecordTypeId);

Or alternatively create a dummy object of the required object ( say account ) and use the standard controller itself as shown below.

Account account = new Account();
account.RecordTypeId = someId;    
PageReference pg = new ApexPages.StandardController(account).edit();

Change the above for any of the other custom or standard objects.

  • I am getting the following error: java.lang.UnsupportedOperationException: You cannot call edit() on a null object – Tamil Oct 13 '15 at 16:42
  • Then i guess the object you are passing is null. Initialize it and try. – AslamK Oct 13 '15 at 17:54
  • Hey @Aslamk. The issue is I have a controller which is calling different VF page based of Record type and now I want to show a standard page layout for one record type. I tried your Account code. I inserted a record and opened the record in edit mode it is going to Infinite loop. – Tamil Oct 13 '15 at 18:18
  • Try passing the nooverride=1 parameter along with the URL and see if it works. – AslamK Oct 14 '15 at 9:32
  • Hey @Aslamk thanks for the reply. I tried that it is going to default record type. I have 5 record type. 4 is using VF page and 5th one I need standard salesforce page. – Tamil Oct 14 '15 at 12:30
2

It should have record ID before /e

PageReference('{RecordID}/e?retURL='+Apexpages.currentPage().getParameters().get('retURL')+'&recordType='+RecordTypeId);

  • hi @ashwani thanks for the reply. I'm getting following error message Formula Expression is required on the action attributes. – Tamil Oct 13 '15 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.