+ Start a Discussion
Soundar Raj PonpandiSoundar Raj Ponpandi 

In-sufficient Access when submitting for an approval

Hi,

1. I have configured a standrd approval process.
2. Triggered this approval process with customize button.
3. I am facing an issue with following scenario.

A. Created a record by using "User A".
B. Trying to submit this record by using "User B".
C. User B having an edit access for this record.
D. WHen i am submitting for an approval it's showing "In-sufficient Access " issue.
C. This issue is not replicated if i given a modify all access to "User B - Profile"


What is the actual issue on that ?

Note:
Role is aded in initial submitter.



Regards,
Soundar.
AnudeepAnudeep (Salesforce Developers) 
Make sure the approver has access to the both the object and the specific record. I recommend lookinag this help article on how to troubleshoot such issues
Soundar Raj PonpandiSoundar Raj Ponpandi
Hi Anudeep,


Thanks for your quick response.

I am facing an issue in line which is highlighted by bold, Please review my code and advise me.
 
public class GD_QuoteApprovalController {
    
    @AuraEnabled
    public static GD_Quote__c getQuoteDetails(String quoteId){
        try{
            GD_Quote__c quote = new GD_Quote__c();
            quote = [SELECT Id,GD_Status__c,OwnerId,GD_Quote_Margin__c,GD_Warranty_Years__c,GD_Has_FOC__c,
                     GD_Business_Unit__c,GD_Business_Unit__r.Name,GD_Total_In_AED__c,GD_Sales_Rep__r.ManagerId,CreatedById
                     FROM GD_Quote__c WHERE Id=: quoteId ];
            
            User loggedInUser = [SELECT Id,Name,profile.name FROM User WHERE Id=:userInfo.getUserId()];
            User createdBy = [SELECT Id,Name,profile.name FROM User WHERE Id=: quote.CreatedById];
            string loggedIn = loggedInUser.profile.name;
            string createdByProfile = createdBy.profile.name;
            List<User> approvalUsers = new List<User>();
            
            quote.GD_Sales_Manager__c = quote.GD_Sales_Rep__r.ManagerId;
            //Submitted By Sales Coordinator
            if(loggedIn.contains('Coordinator')){
                quote.GD_Sales_Coordinator__c = loggedInUser.Id;
            }else if(createdByProfile.contains('Coordinator')){
                quote.GD_Sales_Coordinator__c = quote.CreatedById;
            }else{
                quote.GD_Sales_Coordinator__c = loggedInUser.Id;
            }
            
            update quote;
            return quote;
        }catch(Exception e){
            throw new AuraHandledException(e.getMessage());    
        }
    }
    
    @AuraEnabled
    public static void submitForApproval(GD_Quote__c quoteRecord,String approvalComments){
        
        try{
            
            User loggedInUser = [SELECT Id,Name,profile.name FROM User WHERE Id=:userInfo.getUserId()];
            string loggedIn = loggedInUser.profile.name;
            
            User createdBy = [SELECT Id,Name,profile.name FROM User WHERE Id=: quoteRecord.CreatedById];
            string createdByProfile = createdBy.profile.name;
            
            //Submitted By Sales Rep
            if(!loggedIn.contains('Coordinator') && !createdByProfile.contains('Coordinator') ){
                quoteRecord.GD_Skip_Coorinator_approval__c = True;
            }
            
            update quoteRecord;
            
            List<Approval.ProcessSubmitRequest> approvalRequestList = new List<Approval.ProcessSubmitRequest>();
            String approverId;
            
            Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
            req1.setComments(approvalComments);
            req1.setObjectId(quoteRecord.Id); 
            req1.getSubmitterId(); 
            req1.getNextApproverIds();
            approvalRequestList.add(req1);
            if(approvalRequestList.size() >0){
                /*if(createdByProfile == 'GD ME Sales Coordinator' && loggedInUser.Id == quoteRecord.GD_Sales_Rep__c){
                        quoteRecord.OwnerId = quoteRecord.GD_Sales_Rep__c;
                        update quoteRecord;
                }*/
                Approval.process(approvalRequestList);
                
                Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
                Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest();
                
                id submitterId;
                for(ProcessInstanceWorkitem pItem : [Select p.Id,p.ActorId,p.ProcessInstance.SubmittedById from ProcessInstanceWorkitem p where p.ProcessInstance.TargetObjectId =: quoteRecord.Id]){
                    submitterId=pItem.ProcessInstance.SubmittedById;
                    req.setWorkitemId(pItem.Id);
                }
                if(submitterId!=null){
                    list<User> userDetails =[SELECT Id, Name, Profile.Name, UserRole.Name FROM User where Id=:submitterId];
                    /*Created By Coordinator && Submitted By Coordinator*/
                    if(userDetails!=null && userDetails.size()>0 && (userDetails[0].Profile.Name=='GD ME Sales Coordinator')){
                        req.setComments('Approving request for ' + quoteRecord.Name);
                        req.setAction('Approve'); 
                        Approval.ProcessResult result = Approval.process(req);
                    
                    /*Created By Sales Rep && Submitted by Sales Rep*/
                    system.debug('userDetails - ' + userDetails.size() + '  Profile Name '+ userDetails[0].Profile.Name);
                    }else if(createdByProfile == userDetails[0].Profile.Name && userDetails!=null && userDetails.size()>0 && (userDetails[0].Profile.Name=='GD ME Sales Rep' /*|| userDetails[0].Profile.Name=='GD ME Sales Manager'*/)){
                        req.setComments('Approving request for ' + quoteRecord.Name);
                        req.setAction('Approve'); 
                        Approval.ProcessResult result = Approval.process(req);
                        
                     /*Created By Sales Coordinator && Submitted By Sales Rep*/
                    } else if(createdByProfile == 'GD ME Sales Coordinator' && submitterId == quoteRecord.GD_Sales_Rep__c){
                        
                        req.setComments('Approving request for ' + quoteRecord.Name);
                        req.setAction('Approve'); 
                        Approval.ProcessResult result = Approval.process(req);
                        
                        for(ProcessInstanceWorkitem pItem1 : [Select p.Id,p.ActorId,p.ProcessInstance.SubmittedById from ProcessInstanceWorkitem p where p.ProcessInstance.TargetObjectId =: quoteRecord.Id]){
                            submitterId=pItem1.ProcessInstance.SubmittedById;
                            req2.setWorkitemId(pItem1.Id);
                        }
                        req2.setComments('Approving request for ' + approvalComments);
                        req2.setAction('Approve'); 
                        Approval.ProcessResult result1 = Approval.process(req2);
                        
                    }
                }
            }
            else{
                system.debug('**** Not Met ****');
            }
            
        }catch(Exception e){
            system.debug('EXCEPTION ******* '+e.getStackTraceString());
            throw new AuraHandledException(e.getMessage());    
        }
    }
    
}


Regards,
Soundar.