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
Josh GitogoJosh Gitogo 

Error: Illegal assignment from String to Boolean

I am trying to build a trigger that is triggered once a status is changed from a field on an custom object, it should update a chosen field from a related list of that custom object. However, I keep on receving this error. Does anyone know what this means or how I can fix it?
Amit Chaudhary 8Amit Chaudhary 8
it look like you are upodating some value in Boolean variable/Data type to String. Can you please post your code so that we can help you
jigarshahjigarshah
Josh,

Looks like the variable or the custom field to which you are trying to assign a value, belongs to a datatype of type String which different than the one that variable or field belongs to which is a Boolean.

You would be required to typecast the provided value in the datatype of the variable or field to hich this value is being assigned. You could use the following code snippet to do so.
Boolean yourBooleanVar = Boolean.valueOf('true');
Please post your code here, so that we can help you with the exact fix.

Please DO NOT forget to mark this thread as SOLVED if this ANSWER helps resolve your issue.
Josh GitogoJosh Gitogo
Here is my code
trigger updateshippingtrig on Sol_sence_Sample__c (before insert, before update)
{
    If(Trigger.IsInsert || Trigger.IsUpdate)
    {
        for(Sol_sence_Sample__c co : Trigger.New)
        {
            If(	co.Sample_Request_Status__c == 'shipped')
            {
                    co.Shipped__c = 'checked';
            }
        }
    }
}
Amit Chaudhary 8Amit Chaudhary 8
if shipped__c is boolean the try code like below
trigger updateshippingtrig on Sol_sence_Sample__c (before insert, before update)
{
    If(Trigger.IsInsert || Trigger.IsUpdate)
    {
        for(Sol_sence_Sample__c co : Trigger.New)
        {
            If(	co.Sample_Request_Status__c == 'shipped')
            {
                    co.Shipped__c =true;
            }
        }
    }
}

Let us know if this will work
jigarshahjigarshah
Hello Josh,

Since the Shipped__c field on your object Sol_sence_Sample__c belongs to a datatype Boolean and the value you are trying store is of type String, you are facing the error. You will need to comply to the Boolean data type of the Shipped__c field by replacing line # 09 in your code, with the snippet below.
co.Shipped__c = true ;

However, there are some additional updates I would recommend to your code.

1. Ensure that there is only a single Apex trigger on your Sol_sence_Sample__c object. If multiple triggers exist, consolidate them into a single trigger so as to explicity control the sequence of execution of your business logic.

2. Use any of the existing Trigger desing patterns to separate the Trigger invocation logic from the business logic. This helps is compartmentalizing your code and helps it become more reusable.

3. Use the following code snippet for line # 07 in your code to ensure a case insensitive String comparison.
o.Sample_Request_Status__c.equalsIgnoreCase('shipped');
4. I would recommend moving the hard coded Request Status to a custom label or a constant variable by marking it as a private static final variable. This helps your code become open for extension without requiring any code modifications, if the status text undergoes a change or the logic needs to execute for a different status value instead of Shipped.

Sample code using a Custom Label having a name SampleRequestStatus and storing the status value as 'Shipped' would be as follows.
o.Sample_Request_Status__c.equalsIgnoreCase(System.Label.SampleReqeustStatus);

Please DO NOT forget to mark this thread as SOLVED if this ANSWER helps resolve your issue.
Kundan Kumar 118Kundan Kumar 118
Hello All,
 
Can anyone help me i am getting error here 

ERROR : 6. Illegal assignment from String to Boolean
ERROR: 8. Variable does not exist: Bill_Paid__c

public class PatientsAction {
     @InvocableMethod
    Public Static Void TestpatientsAction(List<ID>ids){
    List<Patients__c> patients=[SELECT Bill_Paid__c FROM Patients__c WHERE Id in :ids];
        for(Patients__c pe:patients){
            pe.Bill_Paid__c ='+sfdcTest';
        }
        Update patients.Bill_Paid__c;
    }
}