+ Start a Discussion
Phil Bredeson 8Phil Bredeson 8 

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

Hello,

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');
        pageRef.setRedirect(true);
        return pageRef;
Hope this should help you.

THanks
Sri