24

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!


23

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.


22

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

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 :


11

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 ...


10

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 ...


9

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 ...


9

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 ...


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 ...


7

I finally got it. Instead of approving each record one at a time, I realized I can put all requests in a list before approving them all at once. Set<Id> accIds = (new Map<Id, Account>([SELECT Id FROM Account])).keySet(); Set<Id> pIds = (new Map<Id, ProcessInstance>([SELECT Id,Status,TargetObjectId FROM ProcessInstance where Status='...


7

you can do it by means of Process.. sobjects: ProcessDefinition (Represents the definition of a single approval process.) ProcessInstance (Represents an instance of a single, end-to-end approval process. Use this and the node, step, and workitem process instance objects to create approval history reports.) ProcessInstanceHistory (This read-only object shows ...


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

http://help.salesforce.com/apex/HTViewSolution?id=000187389&language=en_US As per the above document These approval-related options aren’t available in the Salesforce1 app: • Submitting records for approval. • Recalling approval requests. • Reassigning approval requests. • Accessing an approval request from the record view. ...


6

How I have handled this in the past (leaving out the part where we get a set of the record Ids were are processing stored in recordIds): set<Id> existingApprovalsSet = new set<Id>(); list<ProcessInstance> existingApprovals = [SELECT Id, TargetObjectId FROM ProcessInstance ...


6

An alternative solution is to: add a field update to the initial actions of the approval process that sets a boolean custom field is_locked__c in Case to true and another field update when the case leaves the approval process (final accept/reject/recall action to set is_locked__c to false Then the controller merely looks at the is_locked__c field to decide ...


6

The message you get when activating starts with: After activating this approval process, you cannot add or remove approval steps. and the platform appears to enforce that whether or not instances of the approval process are in use. So I think cloning to a new name is the only choice. (You can then delete the original one if there are no instances of ...


6

Liberal use of Maps should reduce it to this: List<Approval.ProcessWorkitemRequest> requests = new List<Approval.ProcessWorkitemRequest> (); //Get Opps Map<ID, Opportunity> opps : New Map<ID,Opportunity>([Select Id from Opportunity where StageName = 'Lost' and Deal_Number__c like 'SLE%']); //Get ProcessInstance Items Map<ID,...


6

You need to filter on ActorId in addition to ProcessInstance.Status in your query on ProcessInstanceWorkItem. SELECT ProcessInstance.TargetObjectId FROM ProcessInstanceWorkItem WHERE ProcessInstance.Status = 'Pending' AND ActorId = :queue2id You can even do an inner-join sub-select and get it all in one query: You cannot add parent relationship data in an ...


6

StepsAndWorkitems is not a type, it is a child relationship name for ProcessInstanceHistory, so type should be ProcessInstanceHistory and not StepsAndWorkitems. Excerpt from the salesforce documentation The nested query references StepsAndWorkitems, which is the child relationshipName for ProcessInstanceHistory in the ProcessInstance object. You ...


5

Calling Apex Metadata API from Post Install Script: Actually calling the metadata API from an Apex Post Install script is going to be problematic, since in order to call the Metadata API (which is a web service) you need to setup a Remote Site setting the customer org to permit the outbound call (which ironically is back to Salesforce servers). While you can ...


5

Here's a trigger on Account that submits an approval process if the Rating is Cold. trigger AccountRecordLock on Account (after update, after insert) { for (Account a : Trigger.New) { if (a.Rating == 'Cold') { // Create an approval request for the account Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); ...


5

The approval process cannot directly trigger the apex trigger. You will need to create a field (e.g. checkbox) that is checked by the approval step in the approval process. Then start a trigger based on that field. Don't forget to reset the checkbox field when the trigger completes. This can be done by the trigger.


5

Nope, triggers themselves can't be set to listen for a change on a specific field. Triggers can be set to fire on before/after insert, update, delete, and undelete events, and will always fire on every occurrence of their specified events. The closest that you'll be able to get to that is to either use a workflow rule instead of a trigger, or perform a ...


5

The main problem with your current try/catch is that an empty catch block is a major anti-pattern. It's not a habit you want to pick up. In terms of reliability, the behavior of this pattern will be consistent. When you have work items, the first one will be returned. When you have none, null will be returned instead. In terms of performance, the try/catch ...


5

This method is used to specify that current record will be submitted to which procress. If one object have multiple approval process and many of them does not match criteria then you will get an exception if you try to submit your record in them. To over come this its better if you specify your particular process to handle the request. As per Salesforce ...


5

Why did the process continue into Approval process 1 even though the gender was female? Ans: Approval process runs based on the defined process orders. So, first it will enter process order 1 and then checks if criteria is matching for which it has been submitted. It that criteria is not matched then it moves to Process order 2 and again checks the ...


5

They will not be guaranteed to fire in the order you see listed, however this will still work out for you. In Considerations for Field Update Actions that covers creating field updates for workflow rules or approval process: Field updates occur before email alerts, tasks, and outbound messages. The result of a field update is unpredictable when a single ...


4

I've just uploaded a new MetadataService.cls with support for this, you can also see in the MetadataSeviceExamples.cls class an example as follows below on how to do this. I'm not 100% what your issue was with your copy of the generated class, but at least you could compare with the one above if your interested. MetadataService.MetadataPort service = ...


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