I'm trying to check if some fields on the lookup records are filled in(not null).

I have a custom lookup field on Lead to Account, let's call it Some_Account__c. I also have a custom button on Lead and when a user clicks on it I want to make a check if all required fields are filled in(note: by required I mean that they are only required at the moment of clicking the button, so they can possibly be empty).

Here's the code snippet of that button:

if ({!OR( ISNULL( Lead.Some_Account__r.My_Custom_Field_1__c ) ,ISNULL( Lead.Some_Account__r.My_Custom_Field_2__c ))}) {
    alert('please fill in the required fields');

So basically I check if any of those fields is empty, and if at least one of them is, I want to show an alert.

However, I get the following error:

Error: Field Lead.Some_Account__r.My_Custom_Field_1__c does not exist. Check spelling.

So the question is: can I somehow access the fields of the lookup records with JavaScript custom button?


Relationship is not available in your javascript so there are 2 solution of this issue.

  1. Create a formula field on Lead object and then test that value inside javascript (IF(!Lead.YOURFORMULAFIELDFROMACCOUNT))

  2. Use Javascript api if you are familiar with to get Account fields

    var contactCheck = sforce.connection.query("SELECT MY_CUSTOM_FIELD__C FROM ACCOUNT WHERE ID = '{!LEAD.Some_Account__c}' limit 1");

    records = contactCheck.getArray("records");


    alert('Field is empty');

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.