• John M
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
I am trying to handle multiple error codes in my REST service. Can anyone guide me if I am doing this correctly.
try {
                  if(Limits.getDmlRows() < Limits.getLimitDmlRows()){
              	  upsert DataUpdate;  
                  }
                  else if((Limits.getDmlRows() >= Limits.getLimitDmlRows()))
                  {
                      RestContext.response.statusCode = 429;
            		  ErrorReturn[] err = new ErrorReturn[]{ 
	           		  new ErrorReturn(DataUpdate.Id, 'Too many DML operations', 'Error updating MessageID ' + msg.MessageId + ': ' + e.getMessage())
                   	};
                    RestContext.response.responseBody = Blob.valueOf(JSON.serialize(err));
		            RestContext.response.addHeader('Content-Type', 'application/json');
                   	break;
                  }
                }

                catch(System.CalloutException e){
                    System.debug(e.getMessage());
                    RestContext.response.statusCode = 403;
                    ErrorReturn[] err = new ErrorReturn[]{ 
                        new ErrorReturn(DataUpdate.Id, 'Forbidden', 'Error updating MessageID ' + msg.MessageId + ': ' + e.getMessage())
                    };
                    RestContext.response.responseBody = Blob.valueOf(JSON.serialize(err));
		            RestContext.response.addHeader('Content-Type', 'application/json');
                    break;
                }
                 catch(System.QueryException e){
                     System.debug(e.getMessage());
                    RestContext.response.statusCode = 404;
                    ErrorReturn[] err = new ErrorReturn[]{ 
                        new ErrorReturn(DataUpdate.Id, 'ID not found', 'Error updating MessageID ' + msg.MessageId + ': ' + e.getMessage())
                    };
                    RestContext.response.responseBody = Blob.valueOf(JSON.serialize(err));
		            RestContext.response.addHeader('Content-Type', 'application/json');
                    break;
                 }
                
                 catch(System.StringException e) {
                    System.debug(e.getMessage());
                    RestContext.response.statusCode = 400;
                    ErrorReturn[] err = new ErrorReturn[]{ 
                        new ErrorReturn(DataUpdate.Id, 'Bad Request', 'Error updating MessageID ' + msg.MessageId + ': ' + e.getMessage())
                    };
                    RestContext.response.responseBody = Blob.valueOf(JSON.serialize(err));
		            RestContext.response.addHeader('Content-Type', 'application/json');
                    break;
                }
                
                 catch(Exception e) {
                  // VALIDATION_EXCEPTION 
                    if(e.getMessage().indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION') >= 0) {
                        RestContext.response.statusCode = 409;
                        ErrorReturn[] err = new ErrorReturn[]{ 
                            new ErrorReturn(DataUpdate.Id, 'Conflict Error', 'Error updating MessageID ' + msg.MessageId + ': ' + e.getMessage())
                    };
                    } else {
                        RestContext.response.statusCode = 500;
                        ErrorReturn[] err = new ErrorReturn[]{ 
                            new ErrorReturn(DataUpdate.Id, 'Internal Server Error', 'Error updating MessageID ' + msg.MessageId + ': ' + e.getMessage())
                        };
                    }
                    RestContext.response.responseBody = Blob.valueOf(JSON.serialize(err));
		            RestContext.response.addHeader('Content-Type', 'application/json');
                    break;
                }

Can some one guide me on how to handle 407, 439 and 403?
Thanks
Hi,
I am new to Lightning please help me with this. I am getting the following error:
Uncaught Action failed: c:LinkToAttachment$controller$preview [action.SetCallback is not a function]
when I try to run my lightning component on button click. Please Help
Here is my Code:
LinkToAttachment.cmp
<aura:component controller = "LinkToAttachment" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
   <aura:attribute name="contentId" type="String" default="0691h0000001LU8AAM"/>
<lightning:button variant="brand" label="Quick Reference Guide" onclick="{!c.preview }" />
</aura:component>
LinkToAttachmentController.js
({
   preview : function(component, event, helper) {
       var action = cmp.get("c.openfile1");
       action.SetCallback(this, function(response){
       var state = response.getState();
           if(state == "SUCCESS"){
               alert("From server: " + response.getReturnValue());
       var Cdid = response.getReturnValue();
       cmp.set("v.contentId", Cdid);
       $A.get('e.lightning:openFiles').fire({
        recordIds: ["v.contentId"]
    });
           }
});
       $A.enqueueAction(action);
   }
})

LinkToAttachment.apxc
public with sharing class LinkToAttachment {
    
    @AuraEnabled
    Public static List<ContentDocument> openfile1(){
        List<ContentDocument> Cdid=[SELECT id FROM ContentDocument 
                             where Title=' Test Document'];
        return Cdid;
    } 

}

Thanks