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
sivapriyaa maniam sivakumarsivapriyaa maniam sivakumar 

Internal Server Error : 550 - Email Service

Hi Everyone,

Requirenment: Every user should recall the approval process.

I follow this link for email service - https://salesforce.stackexchange.com/questions/122989/recall-approval-process-from-apex-for-non-admin-profile

I configured the email service and wrote the apex classes also ( code as below)
 
global class RecallEmailServiceNST implements Messaging.InboundEmailHandler 
{
    public RecallEmailServiceNST(ApexPages.StandardController controller){}
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,Messaging.InboundEnvelope envelope)
    {  
        Messaging.InboundEmailResult emailresult = new Messaging.InboundEmailResult();
        system.debug(email.plainTextBody);
        if(email.subject.containsIgnoreCase('Recall NST'))
        {
            String str = email.subject.normalizeSpace();
            String NSTNumber = str.substring(str.indexOf('-')+1,str.length());
            System.debug('NSTNumber :'+NSTNumber);            
            NST__c con = [Select Id,Name From NST__c WHERE Name=:NSTNumber];
            try
            {        
            List<ProcessInstance> pi = [SELECT Id FROM ProcessInstance WHERE TargetObjectId=:con.Id AND Status='Pending'];  
              System.debug('pi :'+pi );  
            if(pi.size()==0)
                return emailresult;
            List<ProcessInstanceWorkitem> piw = [SELECT Id,ActorId,ProcessInstanceId FROM ProcessInstanceWorkitem WHERE Actor.Email=:email.fromAddress and ProcessInstanceId=:pi[0].Id];            
           System.debug('piw :'+piw ); 
            if(piw.size()==0)
                return emailresult;
            Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();                        
      /*      if(email.plainTextBody.containsIgnoreCase('<approved>'))
            {
                req.setComments('Request Approved by Email Approval..!!');
                req.setAction('Approve');
            }                                    
            else if(email.plainTextBody.containsIgnoreCase('<rejected>'))
            {
                req.setComments('Request Rejected by Email Approval..!!');
                req.setAction('Reject');
            }
            else */if(email.plainTextBody.containsIgnoreCase('<recalled>'))
            {
                req.setComments('Request Recalled by Email Approval..!!');
                 System.debug('Request Recalled by Email Approval..!!' ); 

                req.setAction('Removed');        
                 System.debug('Removed' ); 
            }
            req.setWorkitemId(piw[0].Id);                                  
            Approval.ProcessResult result = Approval.process(req);
            FeedItem a = new FeedItem(ParentId=con.Id,Type='TextPost');  
            if(result.isSuccess())                                    
            {
                a.Body='Email received from Approver and the process was '+result.getInstanceStatus();                
            }
            else if(!result.isSuccess())
            {
                a.Body='Email received from Approver but some error occured, please contact sys admin';
            }
            a.Body+=email.plainTextBody;
            Insert a;
            }
            catch(Exception e)
            {
                system.debug(e);
            }            
        }
        return emailresult;       
    } 
}

Error: 
A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

>>> recallemailservicenst@y-1sgjk0kf5kumx9gjf0ri0ajl9jp654aldvztnd1l5a4q
>>> vbjq7y.0q-cuhyeas.cs64.apex.sandbox.salesforce.com (Undelivered): 
>>> 550 An internal error occured

couls you please assist us to fix the internal server error.

Thanks
sivapriyaa  M S
harsha nandam 8harsha nandam 8

Hi Sivapriyaa,

Can you please suggest me the workaround for this if you got any?

Thanks

sivapriyaa maniam sivakumarsivapriyaa maniam sivakumar
Hi Harsha,

For "every user should recall the approval process", we have used Email service.
We have changed codes and it is working fine.

Please let me know if you are facing the same issue. Will share my code.

Thanks
Sivapriyaa M S