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
Phil Bredeson 8Phil Bredeson 8 

Button with two actions: 1) create record & 2) take user to list view


I am trying to create a button that does two things: (1) create record for Custom Object A & (2) take user to Custom Object B list view.

Can this be done with URL hacking or would we need to write Apex?
siddarth rajsiddarth raj

Hello Phil

I think you can do this in strightforward approach. 

Create command button, add action method let say  createandredirect.

And in the controller implment the method 'createandredirect' with the return PageReference

Body of it should.
1) code to create record A
2) Use Sobject to create Pagerefernce .. For example

Schema.DescribeSObjectResult result = OjectB__c.SObjectType.getDescribe();
        PageReference pageRef = new PageReference('/' + result.getKeyPrefix() + '/o');
        return pageRef;
Hope this should help you.