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
Karthikeyan ChandranKarthikeyan Chandran 

How to block users from Active a Contract record?

Hi,

Here my senario, User 1, User 2.

Contract records are auto created under Opportunity when the stage is closed(I used process builder). The newly created Contract records are filled by the user (User 1), Whenever the user (User 1) update the contract records an Approval email is send to User 2, I have created a approval process that notify another user in my org(User 2) for Approve the Contarct record.

We need to prevent the "User 1" from Active(Standard Button) the Contract records(Non Approved Contract Records) until it's approved by the User 2.

Can this possible to do so? if yes, how. validation rule or a trigger, etc..

Thanks & Regards,
Karthikeyan Chandran
+91-9944676540
AshlekhAshlekh
Hi,

I think you can accomplish this by Trigger.on Contract.

In Trigger you can query on record and find out that record is approved or not.
 
ProcessInstance[] pi = [Select ID, Status, TargetObject.Name, 
                (SELECT Id, ActorId, ProcessInstanceId FROM Workitems),
                (SELECT Id, StepStatus, Comments FROM Steps) From ProcessInstance 
                Where TargetObjectID = 'YOURRECID' AND Status = 'Approved'];

if(!pi.isEmpty){
   record is approved
}

-Thanks
Ashlekh Gera
Vishal Negandhi 16Vishal Negandhi 16

When you build an Approval Process, while the record is submitted for Approval it is also locked and you've to specify who can modify the record during that phase?

I would suggest you check this configuration within your approval process and you can get this accomplished without any additional code.

srlawr uksrlawr uk
I would agree with Vishal, this sounds like the kind of thing you can do with declarative features, without having to resort to a trigger (not that that is nessesarily a bad solution).

At the lowest/softest level, you could use a validation rule to cross check two fields (the status field and some approval status field - which you might have to create, and then set in your final approval actions) - so it would look like this:

User-added image

and that would stop someone from activating a contract when the approved checkbox (which you set in the approval process) is unticked. (Also use some field level security to stop people manually ticking that box).

Stuff like that sounds complicated, but even as a developer, maintaining lots of fragmented triggers can become a bigger (testing) headache in the future!
 
AshlekhAshlekh
Hi,

There other way is 


Hidden Picklist Field Status- Submitted -> Recordtype 1 -> Page Layout 1 -> No Activate Standard Button
After approval of Contract record:
In Final Approval Action update the Hidden Picklist Field Status- Approved. This will fire a workflow and update the Recordtype  and associated Page Layout 2 will have the Activate Standard Button

So, After approval the Activate Button will come into existence.

-Thanks
Ashlekh Gera
 
srlawr uksrlawr uk
Oh, I kind of like that idea too. Nice way to control the presence of the standard buttons.

However, you'd have to make sure the users couldn't manually change the record type (using the "change" link or by editing) - and can you not also "Activate" an order just by changing it's status using the inline editor for the picklist? (ie the button is just one way to activate).

Depending on page layouts to enforce business logic rules is very difficult, because some many things can happen to records outside the page layouts.