Through plenty of trial and error, I've created the functioning trigger in my sandbox. My issue is that I would like to now apply it to my live org but I can't seem to understand the whole apex class thing.
How can I create a class?
The idea behind my trigger is that when an opportunity record is saved, the soql query will look at the picklist value selected in the category field and find an an active vendor or member service account type with a matching name and bring over its salesforce id. Dropping that sfid into my Vendor Name lookup field will allow me to have the relationship between the opportunity and vendor/member service account that I need for other workflow rules and field updates.
trigger Find_Vendor on Opportunity (before insert)
{
for(Opportunity u:trigger.new)
{
if(u.Vendor_Name__c == null)
{
u.Vendor_Name__c = [Select Id From Account
Where (Account_Type__c = 'Vendor'
OR Account_Type__c = 'Member Services')
AND Status__c = 'Active'
AND Name = :u.Category__c limit 1].Id;
}
}
}