21

The answer is, it depends. If you have your code written directly in the trigger or in a class designated without sharing, then the apex code can update records that are locked, regardless of the user who caused the trigger to fire. I tested by creating a trigger on Contact that updates a field on the Contact's Account. When the Account is locked, I can ...


21

From Winter16 you can check this using the Approval system class Pass it the Id of a record you want to check if is locked or not: Approval.isLocked(recordId); Make sure you set the class api version to 35.0 or higher!


20

This came out in Winter16. It's part of the approval class Approval.isLocked(recordId) This method can also accept List<Id>, SObject, or List<SObject>. You can also now lock and unlock them from Apex. See the documentation on the Approval class.


16

You need to go to Setup->Create-> Workflows and Approvals -> Process Automation Settings and set checkbox Enable record locking and unlocking in Apex as true More information here.


14

You will be able to pull/push the approval process using a the following package.xml. The ApprovalProcess element will pull down the Approval Process and the Workflow element will pull down any of the actions that are referenced in the Approval Process for that action. Replace CustomObject__c with whatever object(s) your approval processes are on, this will ...


13

Working on Salesforce1 too, and I found that for you. I hope it's what you are looking for. Works perfectly for me. Here is the source doc <script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script> <script> Sfdc.canvas.publisher.subscribe({name: "publisher.showPanel", onData:function(e) { Sfdc....


12

You can submit multiple Records for approval, sample code below. List<Approval.ProcessSubmitRequest> requests = new List<Approval.ProcessSubmitRequest> (); for (Id oppId: opportunities) { Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for ...


12

Might this statement in the docs for the ProcessRequest class, the parent class for the ProcessSubmitRequest, provide some insight? If the next step in your approval process is another Apex approval process, you specify exactly one user ID as the next approver. ProcessRequest class Update: One method to do this would be to rearrange the trigger ...


12

As of Winter '16, this is now possible through APEX. (Release Notes) It can be enabled by going to Setup > Create > Workflow & Approvals > Process Automation Settings :


10

This mechanism will work for both master detail and lookup without resorting to code: Create a new checkbox field on the parent record of 'Locked' or similar with a default value of unchecked. Add an initial submission action on your approval process that sets the value of 'locked' to true Add a validation rule to the child record that checks isnew() and ...


10

If the object you are working on is a the detail of a Master-Detail then you cannot have a queue for it. From the documentation: The Owner field on the detail and subdetail records is not available and is automatically set to the owner of the master record. Custom objects on the “detail” side of a master-detail relationship can't have sharing rules, ...


9

You can edit the approval page layout once you have created your approval process. When viewing the approval process detail, click on the Edit button, and then the Approval Page Layout option from the menu: That will take you through to a screen with a multi-select picklist of the fields on the page, and you should be able to choose your picklist field ...


9

This is all definitely possible inside Salesforce's approval process. It utilizes approval steps. This would utilize a 3 step approach. Here is a Youtube demonstration of a scenario of requiring two approvers. Here is another Youtube video from a Dreamforce session that goes more into depth on workflow and approval process. Finally, here are some more ...


9

EDITOR NOTE As mentioned in other answers, this feature is now possible out of the box as of Winter '16. Original Answer not out of the box. What we did in a client project was: Create RecordLockStatus__c picklist field with valuess [UNLOCKED, IN_APPROVAL, LOCKED] Create UnlockToken__c text field Create an approval process with entry criteria ...


9

You could create an "In Approval Process?" checkbox and set it to true in the Initial Submission Actions and then set it to false in the Final Approval, Rejection, and Recall Actions of approval processes. SF has added isLocked method in System.Approval class from Spring 16 (Api level 36). So it is now possible to check if the record is locked or unlocked ...


8

This is possible by setting the action on a ProcessWorkItemRequest to "Removed". Depending on the configuration of your approval process this option may only be available to system administrators. If the approval process is set to "Allow submitters to recall approval requests" then the submitter of the record can also recall it. Sample apex: Approval....


8

Approval processes route a record to one or more approvers, specifying the steps necessary for a record to be approved, and who must approve it at each step. In a typical approval process (what you're calling a "static" approval process), the approvers at each step are explicitly specified in each step approval process. You have a little flexibility -- for ...


8

Formula fields aren't actually stored in the database - this is what allows things like TODAY() functions and $User variables that are dynamic based on who and when it's accessed. Technically speaking they're calculated on the fly when the record is queried. Because of this locking a record doesn't prevent them from having updated values. Likewise a ...


8

By design, Approval Processes only allow either a System Administrator and/or the Initial Submitter to recall the submission. Per Salesforce documentation: However, to answer your question How can I make this work for any user? you will need your Apex code to change the context user to be a System Administrator. One way to achieve this is by using Apex ...


8

See Create an Approval Step. In step 10 it says: Require unanimous approval from all selected approvers. The record is only approved if all of the approvers approve the request. The approval request is rejected if any of the approvers reject the request. So you need to specify multiple approvers in the Automatically assign to approver(s) option and ...


7

For problems like these, I like to back up and do the following: Check each condition individually to isolate the problem Check the ISPICKVAL literals for typos Double-check the comparisons to make sure I didn't reverse the greater-than/less-than signs Re-format the expression, providing indentation to help see the blocks grouped together Write the ...


7

Thanks for looking at my blog post. From looking at your question, may I ask first, are you looking to make comments mandatory for approvals, rejections or both? In my example I only make comments mandatory on rejections. If you are looking to do this for approvals or both, then you would need to adjust the trigger code accordingly, including altering the ...


7

The query which you are attempting to execute is using a child relationship name, StepsAndWorkItems , which isn't valid in that context. StepsAndWorkItems is the child relationship name for ProcessInstanceHistory under the ProcessInstance object. The underlying objects are ProcessInstanceStep and ProcessInstanceWorkItem. You can query those two objects ...


6

I believe you would need to create a Queue for that Custom Object, before it becomes available to assign to. (A Case Queue must exist straight off the bat, which is why you wouldn't have had to create one) http://login.salesforce.com/help/doc/en/setting_up_queues.htm


6

This is how I solved this issue: public Boolean doesOpportunityHavePendingApproval() { return ![ Select Id From ProcessInstance WHERE TargetObjectId =: theOpportunity.Id AND Status = 'Pending' ].isEmpty(); }


6

The IsLocked field is not currently exposed via the API or SOQL, but there's an idea on the IdeaExchange to add that functionality. In the meantime, you can work around that by created a custom field on the object called In_Approval_Process__c, and edit your approval process to set this field when the record is submitted for approval and clear it after ...


6

I believe it's possible to query for the existence of an Approval Request related to your record, I believe this is via: ProcessInstance. Try checking out: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_process_example.htm Additionally, you could write a method to attempt to update the record, and trap the exception message ...


6

Roles If you've set the approval to "anybody from the Queue" make sure you're OK with who's in the Queue exactly. Easiest is to click "view all members". Roughly speaking expect that all managers of your queue members (all the way to CEO or whatever is your top role) will have access too. I honestly don't know if it also works when an User is set as the ...


6

Solved. Intial Submitters were set to Opportunity Owner. The difference results experienced between environments was due to Profile differences. One User had Modify All permission on Opportunities and did not receive the error (obviously). Removed 'Modify All' on Opportunities and added a public group to Intial Submitters. Thanks for your help.


6

Is there a chance you created the approval process but don't have it activated? Does your account meet the entry criteria for your approval process? This error is thrown when an object is attempted to be submitted for approval and no approval process can be found, either because it isn't activated or your object doesn't meet the entry criteria. You can not ...


Only top voted, non community-wiki answers of a minimum length are eligible