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
UrvikUrvik 

Error: Compile Error: Illegal assignment from Schema.SObjectField to String at line 16 column 7



public with sharing class ComplaintInquiriesHandler { private boolean isExecuting = false; private integer batchSize = 0; public ComplaintInquiriesHandler(boolean triggerIsExecuting, integer size){ isExecuting = triggerIsExecuting; batchSize = size; } public void OnBeforeUpdate(Complaint_Inquiries__c[] oldComp, Complaint_Inquiries__c[] updatedComp){ For(Complaint_Inquiries__c Compl:updatedComp) { if (Compl.Copy_From_Account__c == true){ list<Account> Acc = [Select id,BillingStreet from Account where Name=:Compl.Business_Name__c limit 1]; if(Acc!=null){ Compl.Business_Address__c = Account.BillingStreet; } Compl.Copy_From_Account__c = false; } } } }

 Could someone please assist? I am not able to figure out the issue here.

VaasuVaasu

Hey,

 

You are trying to access list directly instead of account record.I suggest the code should be "Compl.Business_Address__c = acc.BillingStreet;" not "Compl.Business_Address__c = Account.BillingStreet;"

UrvikUrvik
No it didn't work. Please be informed that the Account is a lookup field.
k_bentsenk_bentsen

See if changing the line as to below works:

 

Compl.Business_Address__c = (String)Account.BillingStreet;
UrvikUrvik
Nopes..No luck this time...I believe that the error because the account is a lookup field. I am not able to figure out how to reference the lookup in my controller.
k_bentsenk_bentsen

Compl.Business_Address__c = acc[0].BillingStreet;

 

VaasuVaasu

Try what ben suggested...That should work

UrvikUrvik

I was able to save my controller finally but now the trigger is giving me an error.

 

This is the error

Error: Compile Error: Method does not exist or incorrect signature: [ComplaintInquiriesHandler].OnAfterInsert(LIST<Complaint_Inquiries__c>, LIST<Complaint_Inquiries__c>) at line 5 column 2

 

trigger EventTrigger on Complaint_Inquiries__c (after insert, before update,before insert) {
ComplaintInquiriesHandler handler = new ComplaintInquiriesHandler(Trigger.isExecuting, Trigger.size);

 if(Trigger.isUpdate && Trigger.isBefore){
 handler.OnAfterInsert(Trigger.old, Trigger.new);
 }
}

 

VaasuVaasu
Can u send the code in ComplaintInquiriesHandler class
UrvikUrvik

Here you go..

 

public with sharing class ComplaintInquiriesHandler {
    private boolean isExecuting = false;
    private integer batchSize = 0;

    public ComplaintInquiriesHandler(boolean triggerIsExecuting, integer size){
        isExecuting = triggerIsExecuting;
        batchSize = size;
    }
    
  public static void OnBeforeUpdate(Complaint_Inquiries__c[] oldComp, Complaint_Inquiries__c[] updatedComp){
      For(Complaint_Inquiries__c Compl:updatedComp)
      {  
    if (Compl.Copy_From_Account__c == true){
   list<Account> Acc = [Select id,BillingStreet from Account where Name=:Compl.Business_Name__c limit 1];
   if(Acc!=null){
      Compl.Business_Address__c = Acc[0].BillingStreet;
   } 
   Compl.Copy_From_Account__c = false;
}
       }
      }
  }

 

 

VaasuVaasu
change the method name to "OnBeforeUpdate" instead of "OnAfterInsert" in the trigger
UrvikUrvik

I already tried that but it says

 

Static methods cannot be invoked through an object instance: OnBeforeUpdate(LIST<Complaint_Inquiries__c>, LIST<Complaint_Inquiries__c>) at line 5 column 2

VaasuVaasu
use OnBeforeUpdate in the trigger instead of OnAfterInsert
VaasuVaasu
use this

trigger EventTrigger on Complaint_Inquiries__c (after insert, before update,before insert) {
ComplaintInquiriesHandler handler = new ComplaintInquiriesHandler(Trigger.isExecuting, Trigger.size);

if(Trigger.isUpdate && Trigger.isBefore){
ComplaintInquiriesHandler.OnBeforeUpdate(Trigger.old, Trigger.new);
}
}
Sgt_KillerSgt_Killer

Try the below snippet :-

 

//Set to collect all the Business Name

Set<String> ciset = new Set<String>();

 


public void OnBeforeUpdate(Complaint_Inquiries__c[] oldComp, Complaint_Inquiries__c[] updatedComp)
{
for(Complaint_Inquiries__c Compl:updatedComp)
{
if(Compl.Copy_From_Account__c == true)
{
ciset.add(Compl.Business_Name__c);
}
}


List<Account> Acc = [Select id,BillingStreet from Account where Name in :ciset];

for(Complaint_Inquiries__c Compl:updatedComp)
{
if(Compl.Copy_From_Account__c == true)
{
for(Account a : Acc)
{
if(Compl.Business_Name__c == a.Name )
{
Compl.Business_Address__c = a.BillingStreet;
}
}
}
else
Compl.Copy_From_Account__c = false;
}
}

 

 

I dont think using a SOQL query inside a for loop is a good idea. So tried to modify the method in the above manner. I didnt compile the above code. Let me know if you face some issues.

UrvikUrvik
I have OnBeforeUpdate in the trigger.
VaasuVaasu
use this

trigger EventTrigger on Complaint_Inquiries__c (after insert, before update,before insert) {
ComplaintInquiriesHandler handler = new ComplaintInquiriesHandler(Trigger.isExecuting, Trigger.size);

if(Trigger.isUpdate && Trigger.isBefore){
ComplaintInquiriesHandler.OnBeforeUpdate(Trigger.old, Trigger.new);
}
}
VaasuVaasu
Urik, DId that work?
UrvikUrvik
Yes it worked but I am not getting the expected result so trying to figure out what is wrong... I am able to save the controller and trigger both but the result is null.