+ Start a Discussion
MattyDHLMattyDHL 

Method does not exist or incorrect signature: [Id].equals(String)

Hi,

I am still new to Apex, and learning more functions and expected this to work:

 

 

trigger DelCustPrevent on Account (before delete) { for (Account a : Trigger.old) { if (a.IF_SAP__c != NULL && a.RecordTypeId.equals('0122000000000lZAAQ')){ a.addError('You do not have permission to delete this record'); } { } } }

 

Can someone please help me, the error is on the RecordTypeId check, how can I make this  Boolean check?

 

Regards

 

Matt

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

The equals method isn't available on the ID data type, you should use the == operator instead.

 

 

trigger DelCustPrevent on Account (before delete) { for (Account a : Trigger.old) { if (a.IF_SAP__c != NULL && a.RecordTypeId==('0122000000000lZAAQ')){ a.addError('You do not have permission to delete this record'); } { } } }

 

 

 

 

All Answers

JimRaeJimRae

The equals method isn't available on the ID data type, you should use the == operator instead.

 

 

trigger DelCustPrevent on Account (before delete) { for (Account a : Trigger.old) { if (a.IF_SAP__c != NULL && a.RecordTypeId==('0122000000000lZAAQ')){ a.addError('You do not have permission to delete this record'); } { } } }

 

 

 

 

This was selected as the best answer
MattyDHLMattyDHL

Thanks for the reply.

 

Exactly, I tried the == with quotes but not brackets around the quotes, i tried like this:

if (a.IF_SAP__c != NULL && a.RecordTypeId=='0122000000000lZAAQ'){

 

Thanks

 

If you have the time, can you help me to understand why I need to use the brackets there?


Again, much appriciated.

 

Matt

'

JimRaeJimRae

Not sure about that, I tried it successfully both ways. The only reason I used the parens was because I copied your sample code and replaced the .equals with the ==.

Did you get an error when you did it that way?

MattyDHLMattyDHL

Hi,

 

Yup, something like "AND operator can only be applied to boolean"

 

hmmm, strange, cause i tried that at first, then i searched and found information about using the .equals

 

Matt

JimRaeJimRae
I Have only seen that type of error message when I forgot to use the double equals == and used the single = (which is for assignment) instead.
MattyDHLMattyDHL
I thought I used double, but i must not have. Again, thanks for you help.

Matt