You can start by defining an Account object that you would refer in your createShipment method.
public with sharing class ShipmentExtension {
ApexPages.StandardController standardController;
String accountId;
public Account objAccount {get; set;}
Next, in your constructor you can initialize objAccount.
public ShipmentExtension(ApexPages.StandardController standardController) {
this.standardController = standardController;
this.accountId = ApexPages.currentPage().getParameters().get('accountid');
this.carrier = 'Private Freight'; /* Default Option */
if(!string.isEmpty(this.accountId)){
objAccount = [SELECT Id, Name, Owner.Name, ShippingStreet, ShippingCity, ShippingCountry, ShippingState, ShippingPostalCode FROM Account
WHERE Id = :this.AccountId];
} else {
objAccount = new Account();
}
}
In your VF page, you would need to use {!objAccount.}
instead of {!Account.}
In you createShipment() method, you would be able to get the updated values when you refer the objAccount object.
new_shipment.Account__c = objAccount.Id;
Finally, instead of returning null, you would return the PageReference of the new shipment record.
Ok, so I found the problem. It was in this line:
return new PageReference('/setup/ui/recordtypeselect.jsp?ent=Account&nooverride=1');
When I removed the override of the new button and tried to create a new Account, I saw this URL:
https://cs18.salesforce.com/setup/ui/recordtypeselect.jsp?ent=Account&retURL=%2F001%2Fo&save_new_url=%2F001%2Fe%3FretURL%3D%252F001%252Fo
Note this save_new_url parameter in there. After I added it to my PageReference
everything works as it is supposed to(some profiles get a custom VF page and others go to standard record type selection and standard new layout):
return new PageReference('/setup/ui/recordtypeselect.jsp?ent=Account&nooverride=1&save_new_url=%2F001%2Fe');
And actually I don't even need this if
anymore(that checks for RecordType parameter), so the code was reduced to this:
public PageReference redirect() {
if (!shouldSkipRecordTypeSelection(u)) { // a simple if that checks user's profile and returns true if record type selection should be skipped
return new PageReference('/setup/ui/recordtypeselect.jsp?ent=Account&nooverride=1&save_new_url=%2F001%2Fe');
}
return null;
}
EDIT
As sfdcweb mentioned is his comment, this will not work for custom objects by simple changing the ent property to MyCustomObject__c
.
To make it work for custom objects too you will have to use the 15 character id of that custom object. To find it, go to:
Then, just replace the ent=Account
with ent=01I8E0000008XjE
Best Answer
Try this:
SELECT CustomObjectId FROM CustomObjectUserLicenseMetrics WHERE CustomObjectName ='[YOUR_OBJECT_NAME]'