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
Suman KuchSuman Kuch 

DMLs after future callouts not working


 
Hi,
I have an API that has callouts and DMLs, these DMLs executes after future callouts but not executing. Is there any limitations on that? Please check the code where I'm doing wrong.
 
@future(callout=true)
private static void uploadFile(String objFolderName,ID objID, String attachID, String custBoxAttachID, String fName) {
        try{
            String HomeFolderID = Label.HOME_FOLDER_ID;
            createFolderIn(objFolderName,'sObjectName',HomeFolderID);
            system.debug(' request body '+'FolderID='+sObjectFolderID+'&AttachID='+attachID);
            String reqBody = 'FolderID='+sObjectFolderID+'&AttachID='+attachID+'&FileName='+fName;
            String endPointURL='https://thirdpartywebsite.com';
            sendHttpRequest(endPointURL,reqBody,'POST'); //this httpcallout
          
            system.debug(' Attachment.getId() :: '+custBoxAttachID);
            BoxAttachment__c custAttachment = [select id from BoxAttachment__c where id = :custBoxAttachID];
            custBoxAttachment.BoxFileID__c = boxFileID;
            custBoxAttachment.Status__c = 'Success';
			
            update custBoxAttachment; //This is not working
            
			Attachment att = [select id from Attachment where id = :attachID];
			
			delete att;//This is not working
            
			att = [select id from Attachment where id = :attachID];
            system.debug(' after delete :: '+att);
            system.debug(' Successfully completed '+custBoxAttachment.Status__c);
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,
                'Cannot upload attachment, Please check with Admin.'));
            System.debug(' Cannot uploadFileToBox: actual error is '+e.getMessage());
        }
    }

Please check and give me clue what I'm doing wrong here.

Thanks in advance.
Suman KuchSuman Kuch

Well I was able to update object, but still not able to delete Attachment.
I changed the line no 12;instead of returning just ID, I used Id, BoxFile__c,Status__C then I was able to update. Please advice on Delete record
 
BoxAttachment__c custBoxAttachment = [select id,BoxFileID__c,Status__c from BoxAttachment__c where id = :custBoxAttachID]; 
custBoxAttachment.BoxFileID__c = boxFileID; custBoxAttachment.Status__c = 'Success'; update custBoxAttachment;