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
AJHAJH 

Assign Owner to custom object record based on a lookup table

I'm very new to trigger building, but I think this is my only option for fulfilling this process.

 

We'd like to create a lookup table that is managed independantly.  A REGION table will contain a region name, and an "assignment" person.  (lookup to the USER object).

 

Next, we'll have a "zip codes" table that needs to include the "assignment" person based on the REGION (lookup to the REGION table).

 

I've tried to set this up with workflow, but there's no way to have the USER lookup variable based on the region without making a million rules.

 

Here are the tables i'd like after the trigger run (simplified)  (e.g <field name> (<data1>, <data2>, etc.))

Region Table

Region Name (region1, region2, region3)

Assignment (George, Jim, Stacy)

 

Zips Table

Zip Name (11111,22222,33333,44444,55555)

Region (region1, region1, region2, region2, region3)

Assignment (George, George, Jim, Jim, Stacy)

 

The region table is created first, then zip rows are created and assigned regions.  After a region is set, the assignment field is populated by the trigger.

 

Thanks for any help from the community!

Aaron

IspitaIspita

Hi AJH,

As you were mentioning truly a trigger is the best way forward for you. I assume 

 

trigger tocAccountTrigger on Account (before update)

{
   if (Trigger.isBefore)

   {
   for (Account a : Trigger.new)

       {
              // logic for assignment of owner 

               // based on the region enetered query the region table and get the corresponding record 

              zip z = [Select zip, region, assignment from ZipTable where zip=:trigger.new .zipcode limit 1];

             Region re = new Region();

             re.RegionName= z.region,

             re. Assignment=z.assignment;

              Insert re;

        }
    }
}

 

Hope this helps.