I have a custom object Vendor__c and on that object I have a lookup field to Accounts. I want to populate that Accounts lookup field with the account related to another lookup field Projects__c which comes from a custom object projects. I am very new to Apex but this is what I have so far:
trigger Vendor__c {
Set<Id> accountIds = new Set<Id>();
for(proj from trigger.new){
accountIds.add(proj.Customer__c);
}
List<Account> accountsWithProj = [SELECT Id, (SELECT Customer__c FROM Projects__r) FROM Account WHERE Id IN :accountIds];
for(account from List<Account> accountsWithProj = [SELECT Id, (SELECT Customer__c FROM Projects__r) FROM Account WHERE Id IN :accountIds];){
vendor.Account__c = null;
if(!vendor.Project__c.isEmpty()){
vendor.Account__c = vendor.Project__r.Customer__c;
}
}
update accountsWithProj;
}
Can someone assist me with trying to get this field to auto-populate with this information? I am open to new suggestions as well. Thank you!