0

I have 3 objects object 1, object 2 and user.

object 2 has a lookup to user and object 1 has a lookup to object 2. I want to submit a record of type object 1 for approval to the user as defined by object2. Is this possible by any standard functionality of salesforce. I am fairly new with salesforce and any help will be really appreciated.

0

The way I've accomplished this is to use a Trigger. First, create a User lookup on object 1, it can be completely invisible to users. Add this field as the "automatically assign to approvers" field in your approval process step. Then, add a trigger to object 1 looking something like this:

trigger AssignApproval on object_1__c(before insert, before update)
{
    List<ID> obj2Ids = new List<ID>();
    for(object_1__c obj : Trigger.New)
    {
        obj2Ids.add(obj.Object_2__c);
    }
    Map<ID, Object_2__c> obj2Map = new Map<ID, Object_2__c>([select Approver__c from Object_2__c where ID in :obj2Ids]);
    for (object_1__c obj : Trigger.New)
    {
        if (obj.Object_2__c != null)
        {
            obj.Approver__c = obj2Map.get(obj.Object_2__c).Approver__c;
        }
     }
}

Now whenever the object is updated, it will get the approver from object 2. If the approver in Object 2 can change and that should be reflected in Object 1, you can also add a trigger to Object 2 which finds any object 1 records associated to it and updates them..

  • @IllusiceBrian I understand your code, I just want to know one other thing. I wanted to use standard functionality because I have a 2 step approval process, for the first step it goes to a static user, for the second step it goes to a dynamic user :-( – Rimii Apr 13 '17 at 13:18
  • @Rimii Sorry, I forgot to add the step to add the new field to your approval process. You can repeat this with as many approval process steps as you like, just add more lookups to object 1. – IllusiveBrian Apr 13 '17 at 13:30
  • It can be done using visual workflow, or even process builder, though they still (as of last year) teach it in the intro to object oriented programming for admins course. – gorav Apr 13 '17 at 19:36
1

Yes you can do this with process builder, though it's likely better with flow.

What you are describing is also known as a "dynamic approval process".

You need to add a lookup to user on object1 (lets call it approver__c) and reference that field as the approver in your approval process.

Then use process builder to update approver__c to the user on object2, and have process builder itself submit the record for approval.

You can use a checkbox to launch the process.

Or you can build a button that launches a flow to update the checkbox, or you can do the whole thing in flow, which gives you some more options.

You might want to add logic to evaluate if the user is inactive and if so, pop a screen to the user, etc. Flow let's you do this.

There is a free hands on training for this that I helped build, from dreamforce 15, available here (scroll down for the free ones)

https://www.salesforce.com/campaigns/success-services/sfu-hands-on-training-sessions.jsp

-1

No it is not possible with standard fuctionality. however you can try it using Trigger

  • it can be done declaratively, though they still (as of last year) teach it in the intro to object oriented programming for admins course – gorav Apr 13 '17 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.