function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VisithraVisithra 

Kindly help in trigger, am getting this error for if rating is hot and Annual revenue is blank i need to set as 20k, where did i made mistake

Here is my code,
When BEFORE_INSERT
        {
            for(Account accRecord: Trigger.new){
                if(accRecord.Rating=='Hot')
                {
                    if(String.isBlank(accRecord.AnnualRevenue))
                    {
                        accRecord.AnnualRevenue=20000;
                    }
                }
            }
        }

Getting error as:
Method does not exist or incorrect signature: void isBlank(Decimal) from the type String
SubratSubrat (Salesforce Developers) 
Hello ,

The error occurs because the isBlank method in the String class does not accept a Decimal argument. The isBlank method is used to check if a String is empty or contains only whitespace.

In your code, the AnnualRevenue field is of type Decimal, so you need to use a different approach to check if it is blank or has a value.

Here's the updated code for your trigger:
trigger SetAnnualRevenue on Account (before insert) {
    for (Account accRecord : Trigger.new) {
        if (accRecord.Rating == 'Hot' && accRecord.AnnualRevenue == null) {
            accRecord.AnnualRevenue = 20000;
        }
    }
}
In the updated code:

The trigger operates on the Account object before the records are inserted (before insert).

The loop iterates over the Trigger.new collection, which contains the records being inserted.

For each Account record, it checks if the Rating field is 'Hot' and if the AnnualRevenue field is null (blank).

If both conditions are true, it sets the AnnualRevenue field to 20000.

Hope this helps !
Thank you.
Arun Kumar 1141Arun Kumar 1141

Hi visi,

The error you're encountering indicates that the isBlank() method is not available for the Decimal data type. The isBlank() method is specifically designed for String data types. To check if a Decimal field is blank or empty, you can use a different approach.

Here's an updated version of your trigger code that performs the desired check for AnnualRevenue:
 
trigger AccountTrigger on Account (before insert) {
    for(Account accRecord : Trigger.new) {
        if(accRecord.Rating == 'Hot') {
            if(accRecord.AnnualRevenue == null) {
                accRecord.AnnualRevenue = 20000;
            }
        }
    }
}


In this code, the isBlank() method is replaced with a null check (accRecord.AnnualRevenue == null) to determine if the AnnualRevenue field is empty. If it is empty, the code sets the AnnualRevenue to the desired value of 20000.

Make sure to save and deploy the updated trigger code to your Salesforce org to apply the changes.

Hope this will be helpful.
Thanks!