• Mat Kwok
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies

Hey guys,

 

Is there a way, through code or otherwise, to keep track of last field modified in addition to last modified date?

 

I was thinking of something in the trigger, but the only way I could come up with was to do a comparison of the old and new values of each field individually.

 

Thanks

 

EDIT: Scratch that, kind of irrelevant since you can edit multiple fields at once. Let me rephrase then, is there a way to find out what field(s) were edited via Apex?

Hi all,

 

Is it possible to execute another batch apex job in the Finish method of a batch class?

 

 

global class SomeBatchJob implements Schedulable, Database.Batchable<SObject> 
{
	
    global void execute(SchedulableContext ctx)
    {       
        Database.executeBatch(new SomeBatchJob(),1);              
    }
    
    global Database.QueryLocator start(Database.BatchableContext ctx)
    {
        // Some query
    }
    
    global void execute(Database.BatchableContext ctx, List<SObject> items)
    {
        // Operations
    }	    
    
    global void finish(Database.BatchableContext ctx)
    {  
         Database.executeBatch(new SomeOtherBatchJob(),1);
    }   
}

 In essence, I want to be able to daisy-chain 3 schedulable batch jobs, instead of scheduling 3 separate APEX classes. Is this allowed?

 

Hey guys,

 

I stored some sensitive data in a custom setting using Crypto.generateAesKey(256) and Crypto.encryptWithManagedIV().

 

I also stored the generated key in another protected custom setting hoping to be able to retrieve this key at a later time to decrypt the information I stored earlier.

 

The problem I'm running to is this: the process of turning the key into a string for storage and then back into a blob for use in decryption makes the key invalid. It keeps telling me that the size doesn't match.

 

What's the standard procedure for storing encrypted data and then decrypting it later in another class?

 

Any help would be really appreciated.

Has anyone been able to successfully make call outs to AWS or MWS using the Crypto class to generate signatures?

 

I keep getting SignatureDoesNotMatch return message. I've attached my code below, please let me know if I'm doing anything wrong.

 

 

	public static String timestamp;
	public static String AWSSignature;
	
        public static void testConnection(){
		HttpRequest req = new HttpRequest();
		
		String endpoint = 'https://mws.amazonservices.com';
		
		calculateTimeStamp();

		String request = 'AWSAccessKeyId=' + EncodingUtil.urlEncode(accessKeyId, 'UTF-8') + '\n' +
				'&Action=' + EncodingUtil.urlEncode('GetReportList', 'UTF-8') + '\n' +
				'&Marketplace=' + EncodingUtil.urlEncode(us_marketplaceId, 'UTF-8') + '\n' +
				'&Merchant=' + EncodingUtil.urlEncode(us_merchantId, 'UTF-8') + '\n' +
				'&SignatureMethod=' + EncodingUtil.urlEncode('HmacSHA256', 'UTF-8') + '\n' +
				'&SignatureVersion=' + EncodingUtil.urlEncode('2', 'UTF-8') + '\n' +
				'&Timestamp=' + EncodingUtil.urlEncode(timestamp, 'UTF-8') + '\n' +
				'&Version=' + EncodingUtil.urlEncode('2009-01-01', 'UTF-8') + '\n';
					
		generateAWSSignature('GET','GetReportList',request);
		
		endpoint += '?' + 
				'AWSAccessKeyId=' + EncodingUtil.urlEncode(accessKeyId, 'UTF-8') +
				'&Action=' + EncodingUtil.urlEncode('GetReportList', 'UTF-8') +
				'&Marketplace=' + EncodingUtil.urlEncode(us_marketplaceId, 'UTF-8') +
				'&Merchant=' + EncodingUtil.urlEncode(us_merchantId, 'UTF-8') +
				'&SignatureMethod=' + EncodingUtil.urlEncode('HmacSHA256', 'UTF-8') +
				'&SignatureVersion=' + EncodingUtil.urlEncode('2', 'UTF-8') +
				'&Timestamp=' + EncodingUtil.urlEncode(timestamp, 'UTF-8') +
				'&Version=' + EncodingUtil.urlEncode('2009-01-01', 'UTF-8') +
				'&Signature=' + EncodingUtil.urlEncode(AWSSignature, 'UTF-8');
								
		req.setEndpoint(endpoint);
     				  
		req.setMethod('GET');
		
		String responseBody;
		
		Http http = new Http();
		
		HttpResponse res = http.send(req);
		responseBody = res.getBody(); 	
		System.debug(responseBody);	
	}
	
	private static void calculateTimeStamp(){
		Datetime now = Datetime.now();
		
		//format should be like 2006-01-01T12:00:00.000Z
		timestamp = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z';
		System.Debug('Formatted date : '+timestamp);
	}
	
	private static void generateAWSSignature(String verb ,String action,String request){
		/*
		StringToSign = HTTPVerb + "\n" +
                ValueOfHostHeaderInLowercase + "\n" +
                HTTPRequestURI + "\n" +         
                CanonicalizedQueryString <from the preceding step>
                */
		String canonical = verb+'\n'+
				  'mws.amazonservices.com\n'+
				  '/\n'+
				  request;
		
		Blob bsig = Crypto.generateMac('HmacSHA256', Blob.valueOf(canonical), Blob.valueOf(secretAccessKey));
		
		String signature = EncodingUtil.base64Encode(bsig);
				
		AWSSignature = signature;
	}

 

 

 

Hey guys,

 

Is there a way, through code or otherwise, to keep track of last field modified in addition to last modified date?

 

I was thinking of something in the trigger, but the only way I could come up with was to do a comparison of the old and new values of each field individually.

 

Thanks

 

EDIT: Scratch that, kind of irrelevant since you can edit multiple fields at once. Let me rephrase then, is there a way to find out what field(s) were edited via Apex?

Hi all,

 

Is it possible to execute another batch apex job in the Finish method of a batch class?

 

 

global class SomeBatchJob implements Schedulable, Database.Batchable<SObject> 
{
	
    global void execute(SchedulableContext ctx)
    {       
        Database.executeBatch(new SomeBatchJob(),1);              
    }
    
    global Database.QueryLocator start(Database.BatchableContext ctx)
    {
        // Some query
    }
    
    global void execute(Database.BatchableContext ctx, List<SObject> items)
    {
        // Operations
    }	    
    
    global void finish(Database.BatchableContext ctx)
    {  
         Database.executeBatch(new SomeOtherBatchJob(),1);
    }   
}

 In essence, I want to be able to daisy-chain 3 schedulable batch jobs, instead of scheduling 3 separate APEX classes. Is this allowed?

 

I am running a batch apex class that is scheduled to run periodically throughout the week. (It implements the schedulable interface.) As part of the finish method, I am attempting to create and send an email alerting users that the batch class has completed running. The code compiles / saves fine in the Sandbox - and my unit tests run fine in the Sandbox as well. However, we I go to deploy I get the following error that disappears if I comment out the email code:

System.Exception: Error processing messages

Here is the code within the finish method. Any help / thoughts are appreciated.

Thanks
-- Matt

 

global void finish(Database.BatchableContext BC){

List<String> toAddresses = new List<String>();
// Add email string to List
toAddresses.add('marnold@communispace.com');
String subject = 'Batch class run complete';
String body = '';

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setToAddresses(toAddresses);

mail.setSenderDisplayName('Salesforce Outbound Notification');
mail.setSubject(subject);
mail.setPlainTextBody(body);
mail.setUseSignature(false);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}