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

Invalid type?
Hi all, I am trying to create a trigger that will autopopulate my lookup field when a value is selected from the picklist however I am getting these errors and I don't know why.
My lookup field is to contact (which is filtered).

My lookup field is to contact (which is filtered).
What is the difference between Appointment_with__c and Staff__c, looks like both are referncing the same data point, one is picklist and other is lookup?
Is there a possibility that a person may not exist in Staff__c SObject, selected in Appointment_with__c?
Keeping the above perspective, don't see it a good design and also not is also not taking care of null pointers which may endup getting exceptions.
Please also share the code instead of screenshot.
Whenever an Appointmet_with__c is selected, there is nothing in the lookup. I want to autofill with the value in the picklist.
My code is as follows:
trigger Autofill on Event (before insert, before update) {
Set<String> ids = new Set<String>();
for(Event evt: Trigger.New)
{
if(evt.Appointment_with__c != null)
{
ids.add(evt.Appointment_with__c);
}
}
List<Staff__c> dclocation = [SELECT Id, Name FROM Staff__c WHERE Name in: ids];
for(Event evt1: Trigger.New)
{
evt1.Staff__c = dclocation[0].id;
}
}
It is complaining about Staff__c SObject. Is this exist in your org? Can you please verify?
Here is the right way to handle your requirement
first i would try and make the lookup filter optional, it looks like the name which is picked and the related contact are not valid according to the filter on the lookup.
Also i would move the logic into a handler class
Any feedback or update?