Do I need an Apex Class or just a Trigger in order to update a lookup field in Salesforce? -


i working out of sandbox , trying automatically update vendor_rep__c(lookup field) under custom object member_vendor_del__c. update vendor rep when member vendor record created or edited.

i have created visualforce page, starting believe no longer need acheive need.

also, help, have created following code apex class:

public class contactsearch {  public list<contact>searchcontact(string contacttype, string memberstate, string vendorid) {   return [select name contact           contact_type__c = 'vendor rep' , states__c = :memberstate , contact_vendor_id__c = :vendorid limit 1];      } } 

also, after reading several questions posted, few apex developer guide articles, , watching few tutorial videos, created trigger below. (im not sure need class in order achieve need)

trigger vendorrepupdatetrigger on member_vendor_del__c (before insert, before update) {   (member_vendor_del__c u : trigger.new){      if (u.vendor_rep__c == null){          u.vendor_rep__c = [select name                             contact                             contact_type__c = 'vendor rep' , states__c = :member_vendor_del__c.member_state__c , contact_vendor_id__c = :member_vendor_del__c.vendor_id__c limit 1];        }    } } 

i keep getting error message below line 6 in trigger

"invalid bind expression type of schema.sobjectfield column of type string"

what can passed error , trigger on production , working 100%? need apex class?

to update vendor rep when member vendor record created or edited have go trigger.

some code changes required solve issue. reason of error message trying update lookup field string("name" field) instead of id.

on own code if make following changes think issue resolved.

 trigger vendorrepupdatetrigger on member_vendor_del__c (before insert, before update) {      (member_vendor_del__c u : trigger.new){          if (u.vendor_rep__c == null){               u.vendor_rep__c = [select id                                 contact                                 contact_type__c = 'vendor rep' ,                                 states__c = :u.member_state__c ,                                  contact_vendor_id__c = :u.vendor_id__c limit 1];             }       }   } 

but code not bulkify code. make code bulkify soql query outside of loop use soql result inside loop.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -