triggers - How to update the owner name in custom object based on the mobile no -
i need update owner name based on mobile no present in custom object.
in custom object have field called "referral id". it's contain mobile no,the mobile no present in user details.in custom object need change owner name based on referral id(name).
for example custom object created myself put referral id manager mobile automatically change lead owner manager not me.
i try following trigger
trigger ownerupdate on broker__c (before insert,before update) { //instantiate set hold unique deployment record ids set<id> deplomentids = new set<id>(); for(broker__c s : trigger.new) { deplomentids.add(s.referral_id__c); } //instantiate map hold deployment record ids corresponding ownerids map<id, referral_id__c> deploymentownermap = new map<id, referral_id__c>([select id, phone user id in: deplomentids]); (broker__c s : trigger.new) { if (s.owner__c == null && deploymentownermap.containskey(s.referral_id__c)) { s.owner__c = deploymentownermap.get(s.referral_id__c).ownerid; } } }
i got following error error: compile error: invalid type: referral_id__c @ line 11 column 62
the error pretty clear - trying build map of types id
, referral_id__c
. referral_id__c
not type, it's name of field. type of field string
or phone
, whichever 1 picked when created field.
you have other issues. example
set<id> deplomentids = new set<id>(); for(broker__c s : trigger.new) { deplomentids.add(s.referral_id__c); }
is wrong. deplomentids
set of type id
, trying add mobile phone numbers it. phone numbers not ids.
what should query user matches mobile number against referralid , set him owner. like:
for(broker__c s : trigger.new) { user owner = [select id user mobilephone = :s.referral_id__c limit 1]; s.owner__c = owner.id; }
this assumes there's guaranteed 1 user exact mobile number. how deal referrals can't found, or multiple users matching referral, you.
Comments
Post a Comment