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
conpasconpas 

The code failed only in trigger class

Hello, i have a big problem. While I try to execute a simple line of code in the trigger class failed, but if i try to execute the same code in the VISUALFORCE(calling a class) or in the system debug log working fine. WHY???

 

My code is:

 NEWFOLDERINAMAZON newforlder = new NEWFOLDERINAMAZON('holaaaa33');

 

And mi class is:

public class NEWFOLDERINAMAZON {

    public NEWFOLDERINAMAZON(string folder) {

AWS_S3_ExampleController nf = new AWS_S3_ExampleController();
nf.constructor();
List<SelectOption> allBuckets = nf.getBucketNames();

nf.newfolder('testbank51',folder);

    }

}

 

 

And the error is:

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger chase caused an unexpected exception, contact your administrator: chase: execution of AfterInsert caused by: System.AssertException: Assertion Failed: Class.S3.AmazonS3.PutObjectInline_ACL: line 765, column 1

 

 

 

 

Thanks!!

Prafull G.Prafull G.

The error message shows that Test Methods is failing to validate one of the statement (Assert).

 

Can you confirm the folder name passed as parameter is same from class and trigger ?

 

Regards

conpasconpas

Hello, yes, is the same name.

Prafull G.Prafull G.

can you post the code where you are getting error. i.e class "Class.S3.AmazonS3.PutObjectInline_ACL" ?

conpasconpas

Here is:

 

public Boolean PutObjectInline_ACL(String Bucket,String Key,S3.MetadataEntry[] Metadata,String Data,Integer ContentLength,String accessType,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential, String canonicalUserId) {
            
            //S3Request S3XMLSoapRequest=  new S3Request('PutObjectInline');
            S3Request S3XMLSoapRequest=  new S3Request();
           
            S3XMLSoapRequest.soapBody= '<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header/><env:Body>';
            S3XMLSoapRequest.soapBody+= '<PutObjectInline xmlns="http://s3.amazonaws.com/doc/2006-03-01/">';
            S3XMLSoapRequest.soapBody += '<Bucket>' + Bucket + '</Bucket>';
            S3XMLSoapRequest.soapBody += '<Key>' + Key + '</Key>';
           
           
            if(Metadata!=null){
                for(S3.MetadataEntry entry: Metadata)
                   S3XMLSoapRequest.soapBody += '<Metadata><Name>'+entry.Name+'</Name><Value>'+entry.Value+'</Value></Metadata>';
            }
           
            S3XMLSoapRequest.soapBody += '<Data>' + Data + '</Data>';
            S3XMLSoapRequest.soapBody += '<ContentLength>' +  String.valueOf(ContentLength) + '</ContentLength>';
            S3XMLSoapRequest.soapBody += '<AccessControlList>';
           
            if(accessType=='public-read')
                S3XMLSoapRequest.soapBody += '<Grant><Grantee xsi:type="Group"><URI>http://acs.amazonaws.com/groups/global/AllUsers</URI></Grantee><Permission>READ</Permission></Grant>';
            if(accesstype=='public-write')
               S3XMLSoapRequest.soapBody += '<Grant><Grantee xsi:type="Group"><URI>http://acs.amazonaws.com/groups/global/AllUsers</URI></Grantee><Permission>WRITE</Permission></Grant>';
           
            //Default Owner to FULL_CONTROL
            system.assert(canonicalUserId!=null);
            S3XMLSoapRequest.soapBody += '<Grant><Grantee xsi:type="CanonicalUser"><ID>'+canonicalUserId+'</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant>';
           
            S3XMLSoapRequest.soapBody += '</AccessControlList>';
            S3XMLSoapRequest.soapBody +='<AWSAccessKeyId>' + AWSAccessKeyId + '</AWSAccessKeyId>';
            String formattednow = Timestamp.formatGmt('yyyy-MM-dd')+'T'+Timestamp.formatGmt('HH:mm:ss')+'.'+Timestamp.formatGMT('SSS')+'Z';
            S3XMLSoapRequest.soapBody += '<Timestamp>' + formattednow + '</Timestamp>';
            S3XMLSoapRequest.soapBody += '<Signature>' + signature + '</Signature>';
            S3XMLSoapRequest.soapBody +='<Credential>' + credential + '</Credential>';
            S3XMLSoapRequest.soapBody +='</PutObjectInline></env:Body></env:Envelope>';
           
            
            System.debug('SOAP REQUEST BODY: ' + S3XMLSoapRequest.soapBody);
            httpresponse res = S3XMLSoapRequest.makeRequest();
            System.debug('SOAP RESPONSE: ' + res.getBody());
            AWS_XMLDom dom = new AWS_XMLDom( res.getBody() );
            dom.dumpAll();
            
            if(dom.getElementsByTagName('LastModified')!=null){
              System.debug('Successfully uploaded file with PutObjectInline_ACL method');
              return true; 
            }
            else{
                System.debug('Error: Failed to uploaded file with PutObjectInline_ACL method');
              return false;
            }
           
      
       
        }
       
    }

Prafull G.Prafull G.

Can you please make sure that the parameter "canonicalUserId" in method PutObjectInline_ACL is passed correctly. If this value is not set from where the method is called... it will always give you assert error at the statement

 

//Default Owner to FULL_CONTROL
system.assert(canonicalUserId!=null);

 

Please verify the value is passed correctly. If you are doing some SOQL on user to pass the user id and parameter in this method, make sure the user created in production org as well ?