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
bharath kumar 52bharath kumar 52 

Partner user not able to submit for approval through api

Hi All,

Ia m working on a scenario where i need to submit a record for approval through a javascript button. I have tried submitting it for approval as a partner user but i always get an error message when i trigger it from the custom button. I thought of using process builder but that will again affect the order of execution as there are a couple of workflows and triggers running and this might mess it up.
I tried submitting the record through anonymous window and through batch and it got successfully submitted. Based on my understanding i am thinking that it is an issue with the user submitting it and scheduling is the only option. Any workarounds/suggestions will be of much help to me.
Below is the error message and the code i have worked on :
First error: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process was found.: []
//below is the code which i have altered so submit approval request from partner portal

webservice static string thresholdMetCheck (Id DemoId, String DemoAmount){         

         String ret ='';
         String totDemoAmount;
         totDemoAmount = DemoAmount.replace('$','').replace(',','').replace('USD','').replace('CNY','').replace('EUR','').replace('GBP','').replace('JPY','');
         Schema.DescribeSObjectResult drDescribe = Schema.SObjectType.Demo_Registration__c; 
         Map<String,Schema.RecordTypeInfo> rtMapByNamedr= drDescribe.getRecordTypeInfosByName();
         String approvalPhaseRT = rtMapByNamedr.get('Approval Phase').getRecordTypeId();
         if(double.valueof(totDemoAmount) >= double.valueof(System.Label.Threshold_Amount )){
             ret = 'true';
             Demo_Registration__c dr = [Select id, CreatedById, Approval_Status__c,Partner_Account__r.OwnerId,Distribution_Manager__c from Demo_Registration__c where id=:DemoId];
            List<QueueSObject> newDRQ=[select id, QueueId, SObjectType from QueueSObject where SObjectType='Demo_Registration__c' and QueueId = :System.Label.New_Design_Reg_QueueId];
            //There should be only one queue for Demo_Registration__c
                ApexPages.Message errmsg=new ApexPages.Message(ApexPages.Severity.ERROR,'Too many queues on Demo Registration found');
            }else if(newDRQ.size()==0){
                ApexPages.Message errmsg=new ApexPages.Message(ApexPages.Severity.ERROR,'No queue on Demo Registration found');

                dr.Approval_Status__c = 'Unsubmitted'; 
                dr.OwnerId = newDRQ.get(0).QueueId;
                dr.RecordTypeId = approvalPhaseRT;
                Demo_Registration__Share drShare = new Demo_Registration__Share(AccessLevel = 'Edit', ParentId = dr.Id, UserOrGroupId = dr.CreatedById);
                    Database.Saveresult res=Database.update(dr);
                    insert drShare;
                   system.debug('Approval_Status__c in submit logic >>>' +dr.Approval_Status__c);
                }catch(DMLException e){
                    ApexPages.Message errmsg=new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage());
                system.debug('**********OwnerId' + dr.OwnerId);

                SYSTEM.DEBUG('Account owner isnt null'); 
                SYSTEM.DEBUG('Account owner IS null'); 
                return 'No Partner Account associated with this record';
            dr.RecordTypeId=approvalPhaseRT;    //assigning the appropriate page layout    
                Database.Saveresult reslt=Database.update(dr);
                system.debug('dr >>>>> '+dr);
            }catch(DMLException e){
                return 'false';
         //create the new approval request to submit
         Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
         req.setComments('Submitted for approval. Please review.');
         req.setNextApproverIds(new List<Id>{dr.Partner_Account__r.OwnerId});
         // submit the approval request for processing
         Approval.ProcessResult result = Approval.process(req);
             ret = 'false';
         return ret;

ShirishaShirisha (Salesforce Developers) 
Hi Bharath,


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 just instantiate this code. There must already be an approval process in the system for you to be able to run this code.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
bharath kumar 52bharath kumar 52
Hi Shirisha, The approval process is active and the record meets the criteria too. What I observed is that when the record owner submits it for approval it throws me the error message but when I submit it as an admin ( through batch) it runs properly. Also, i have added the owner field as one of the initial submitters but when I remove the owner field and add that "particular user" as one of the initial submitters it seems to work well. Any particular reason that you know of that might be causing this? Thanks, Bharath