function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SunilKumarSunilKumar 

Trigger Lookupfield update

Hi  I Have a requirement

I have Account object and B  is the custom object  , Here My question is Account having the self lookup relation with the name of city(its a lookup field) and in Account object only state(picklist ) is there with few values a,b ,c, I want when ever user insert or update the record and by selecting the picklist value a , Automatically the a is populate in the city (i mean in lookup filed),
I don't want do this one with pointand click , Do this one trigger only

Please give me reply

Thanks 
 
ManojjenaManojjena
Hi Raju,If possible can you post the custom oject Api Name and  the pick list an dlookup field api name .So that we can help you in a better way .
Thanks 
Manoj
SunilKumarSunilKumar
Api names
B__c custom object

State__c picklist
city__c is lookup apinmae
 
SunilKumarSunilKumar
trigger ContactCreation1 on contact (after update) {



    set<id> accids= new set<id>();
    for(contact a:trigger.old){
    
        accids.add(a.id);
    }
    
  list<contact> conlist  =[select id,description,box__c,picklist__c
                            from contact
                            where id in: accids];
   for(contact c: conlist){
   
       c.box__c=c.picklist__c;
   }    
   update conlist;   
   }


in theabove code box__c is acommon firld, and picklist__c is picklist field 


Please do the after update event, 

 
SunilKumarSunilKumar
While doing above trigger i got this error

Apex trigger ContactCreation1 caused an unexpected exception, contact your administrator: ContactCreation1: execution of AfterUpdate caused by: System.StringException: Invalid id: