1

I am trying this on my Custom JavaScript button

IF( '{!Account.recordtype.name}' ='First RecordType'){
     // Do Something 
 }
ELSE{
    // Do something else
 }

and when I click on "Check Syntax" I got this error -

Error: Field Account.recordtype.name does not exist. Check spelling.

Answer : Please correct if I am missing something/doing in wrong way in below code- to get what I want.

    {!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
    var recordtypeResult1 = sforce.connection.query("Select id FROM RecordType WHERE Name='First RecordType'");
    var recordType1 = recordtypeResult1.getArray("records");
    var recordtypeResult2 = sforce.connection.query("Select id FROM RecordType WHERE Name='Second RecordType'");
    var recordType2 = recordtypeResult2.getArray("records");

    if( ('{!Account.recordtypeid}'== recordType1[0].Id || '{!Account.recordtypeid}' ==recordType2[0].Id)
  {
      //DO Something
}  

Any help or suggestions ??!

1

If you don't mind hard-coding the record type ID:

if('{!Account.RecordTypeId}' == '012i0000000xC4AAAU') {
    ...
}

There is no simple way to use the recordtype's name in this context. (You can query to get the ID from the name.)

  • Hard-coding will not work for me, but I will try using Query, Thanks :) – Salesforce Steps Nov 2 '15 at 11:21
  • Please have a look at the updated Question. – Salesforce Steps Nov 2 '15 at 11:32
  • 1
    @NileshMendhe You should be using == not = in your if. – Keith C Nov 2 '15 at 11:47
3

You can create a Formula Text Field in your Account Object (say name it RTName__c) with the formula RecordType.Name which can give you the Record Type Name for the Account record

and then you can use the formula field in your Custom button Javascript code..

IF( '{!Account.RTName__c}' == 'First RecordType'){
     // Do Something 
}
ELSE{
    // Do something else
}
1

Found 3 ways of workaround in situation like this question -

1) Accepted answer of Keith (Query RecordType) -

2) Create Formula Field on object and use it --- (Answered by Vamsi Kirshna)

3) Make use of Custom Settings to store your RecordTypeid's there and then simply compare them like shown below :

 if( '{!$Setup.RecordTypeIDs__c.Account_First_RType__c}'== '{!Account.RecordTypeId}') {
     //Do Something
 }
-1

if('{Account.RecordType}' == 'ABC') works for me on the javascript button.

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.