[SalesForce] Related Object Fields in custom button (URL Hack)

Having a real brain freeze here.

I am using some URL hacking to auto fill some fields on a custom object.

USE CASE

I have a custom object 'Operations Action' that is related to a case. My Case object has the standard Account fieldm but we have an additional custom lookup to account called 'End Customer Account' (End_Customer_Account__c). This is used to hold the actual end customer. Many times they match if the case is for a customer. However for partners, the Partner account would be in the standard Account field but the customer they are logging the case on behalf of would go in the End_Customer_Account__c field.

ISSUE

I am trying to create a simple custom button that auto populates the shipping address of the End Customer Account. The reason that we are not using a formula is that we want the end user to have the ability to overwrite the value. So really just want to set it to the End Customer Account Fields Shipping Address on the Case as a default, and they can overwrite it if they want.

Am I not allowed to use Related objects in custom buttons? This is what I have

/a6M/e?CF00N80000005QYo9={!Case.CaseNumber}
&CF00N80000005QYo9_lkid={!Case.Id}
&CF00N80000005QYo5=
{!IF(ISBLANK(Case.End_Customer_Account__c),
Case.Account,
Case.End_Customer_Account__c)}

&CF00N80000005QYo5_lkid=
{!IF(ISBLANK(Case.End_Customer_Account__c),
Case.AccountId,
Case.End_Customer_AccountId__c )}

&retURL=%2F{!Case.Id}

**&00N80000005QYoN={!Case.End_Customer_Account__r.ShippingStreet}** //NOT WORKING 

I keep getting the

'Error: Field Case.End_Customer_Account__r.ShippingStreet does not
exist. Check spelling'

It works fine if I use the Account Field

&00N80000005QYoN={!Case.Account.ShippingStreet} 

I have know I can create formula fields on the case that pull in the Shipping Address Fields for the related account, and then use those in this custom button, but I would rather not create 6 custom fields on the case just for this custom button.

Am I missing something? Can I not directly access related object fields in this custom button? I can't seem to find any documentation on this and just want to make sure I absolutely have to before creating the formula fields in order to make this work.

Best Answer

I can't actually find any hard documentation to prove it, but it seems that Merge Fields available in Custom Buttons & Links cannot access Related Object Fields, but only those fields on the record in context. I would be appreciative if someone has some links that clearly state this. It seems to be the case, but seeing it stated in documentation would be comforting.

Seeing as that seems to be the case, I decided to use javascript to create the button instead. This is the button that solved the issue.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 

var url = '/a6M/e?CF00N80000005QYo9={!Case.CaseNumber}&CF00N80000005QYo9_lkid={!Case.Id}'

var myquery = "SELECT Id, Name, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry FROM Account WHERE Id = '{!Case.End_Customer_AccountId__c}' limit 1";

result = sforce.connection.query(myquery); 
records = result.getArray("records"); 

if(records[0]){ 
     var EndCustomerAccount = records[0]; 
     url += '&CF00N80000005QYo5=' + EndCustomerAccount.Name;
     url += '&CF00N80000005QYo5_lkid=' + EndCustomerAccount.Id;
     url += '&00N80000005QYoN=' + EndCustomerAccount.ShippingStreet;
     url += '&00N80000005QYoK=' + EndCustomerAccount.ShippingCity;
     url += '&00N80000005QYoM=' + EndCustomerAccount.ShippingState;
     url += '&00N80000005QYoO=' + EndCustomerAccount.ShippingPostalCode;
     url += '&00N80000005QYoL=' + EndCustomerAccount.ShippingCountry;
}else{
     url += '&CF00N80000005QYo5={!Case.Account}';
     url += '&CF00N80000005QYo5={!Case.AccountId}';
     url += '&00N80000005QYoN={!Account.ShippingStreet}';
     url += '&00N80000005QYoK={!Account.ShippingCity}';
     url += '&00N80000005QYoM={!Account.ShippingState}';
     url += '&00N80000005QYoO={!Account.ShippingPostalCode}';
     url += '&00N80000005QYoL={!Account.ShippingCountry}';
}
window.parent.open(url, "_self");
Related Topic