You need to sign in to do that
Don't have an account?

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.
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;"
See if changing the line as to below works:
Try what ben suggested...That should work
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
Here you go..
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
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);
}
}
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.
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);
}
}