• henryCH
  • NEWBIE
  • 25 Points
  • Member since 2006

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 16
    Replies

Hi,

 

I'd like to use HTTP classes to load an image from the web then save it as an Attachment and finally send it attached to an email. At first glance everything seems to work fine. But the picture I receive is obviously a corrupt file. Any ideas what's wrong with my code:

 

 

public class EmailTestCtr {
	
	public Integer totalFileSize {get; set;}
	public Email__c mail {get; set;}
	public String contentType {get; set;}
	public String response {get; set;}
	
	public EmailTestCtr(){
		totalFileSize = 0;
	}
	
	public void loadFile(){
		String url = '';
		
		Http h = new Http();
		HTTPRequest req = new HttpRequest();
        
        req.setEndpoint('http://www.clienthouse.com/images/f106e78f34/CH_location_web1.jpg');
        req.setMethod('GET');
        req.setCompressed(false);
		
		HTTPResponse resp = h.send(req);
		this.contentType = resp.getHeader('Content-Type');
		this.response = resp.getHeader('Content-Length');
		
		System.debug(resp.getBody());
		String body = resp.getBody();
		
		Attachment a = new Attachment();
		try {		
			if(this.mail == null){
				mail = new Email__c(
					Name = 'test'
				);
				insert mail;
			}
			
			a.Body = Blob.valueOf(body);
			a.Name = 'Name';
			a.ParentId = mail.Id;
			a.ContentType = this.contentType;
			insert a;
		} catch(DMLException e){
			ApexPages.addMessages(e);
		}
		
		this.totalFileSize += [select BodyLength from Attachment where Id = :a.Id].BodyLength;
		
	}
	
	public void sendEmail(){
		
		Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
		String[] toAddresses = new String[] {'h.hess@clienthouse.com'};
		email.setToAddresses(toAddresses);
		email.setSubject(this.mail.Name);
		email.setPlainTextBody('Text goes here.');
		List<Messaging.EmailFileAttachment> files = new List<Messaging.EmailFileAttachment>();
		for(Attachment file : [select Name, Body, ContentType from Attachment where ParentId = :this.mail.Id]){
			System.debug('------------>FILE' + file);
			Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
			efa.setBody(file.Body);
			efa.setContentType(file.ContentType);
			efa.setFileName(file.Name + '.jpg');
			files.add(efa);
		}
		email.setFileAttachments(files);
		
		Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
		
	}
	
}

 

 

Thanks and best regards,

Henry

Hi,

 

We tried to implement a single sign on mechanism of a third party web solution using the Crypto.encrypt method. The third party solution requires that the initialization vector is XOR encoded into the first 16 bytes of the transmitted SSO Token. In java this would be done like this:

 

 

for (int i = 0; i < 16; i++) {
   data[i] ^= INIT_VECTOR[i];
}

 

 

where data and INIT_VECTOR would be byte arrays. In Apex there's nothing like a byte array and Blob has no methods at all. The XOR operator ^ does exist in Apex but it can only be used with Boolean expressions and Integers. So I can't just use the Strings and do some wild XOR character operations. Does anybody know how I can implement an XOR encryption like in Java or any other programming language using Apex?

 

Thanks for your help and best regards,

Henry

Hi all,

 

I have some questions regarding basic features I would have expected in Visualforce/Apex:

 

  • How do you determine which record types are available for the current user?
    A list of all available record types for a certain object is pretty useless if you don't know which are atually available for which profile.
  • How do you find out which picklist values a user may see depending on the record type of the current record?
    Again, a list of all available picklist value is usless unless I do not know which of them may be displayed to the current user.

Especially in salesforce instances with lots of record types and record type dependent picklists, it's essential to follow the existing configuration in Visualforce pages / controllers. So any suggestions or workarounds are greatly appreciated.

 

Thanks and best regards,

Henry

 

 

 

Hi everybody,

I'd like to know if it's possible to call an Apex based Webservice method using a standard outbound message?
Seems to be an odd idea at first glance but we have some use cases/situations that would require a minor delay in processing, like a webservice call, and that can not be realised using triggers. So did anybody manage to do this??

Thanks and best regards,
Henry
Hi everybody,
I'm working on an SControl that displays a special printable view including the last five Activities of an Account. The Activity object seems pretty helpful since it combines Event and Task data, the only thing that seems to be missing is a field where the Time of an Event is stored. The Duration is available but does it make any sense without the start time of the Event? So it would be great if you could tell me where to find the time of an Event in the Activity History object.

Thanks and best regards,
Henry
Hi everybody,

I'm currently working on an S-Control that should support language and locale sensitive contents like date formats. I had to find out that almost all fields of the User object are available, but Language and Locale are missing. So from my perspective that means multi-language support for S-Controls is not available. I wonder if there's a good reason for hiding these two fields from the merge functionality and if somebody knows a workaround? And no, an API call in order to get the full User info is not an acceptable workaround.

Thanks and best regards,
Henry
Hello everybody,

I'd like to display a pop-up window with a progress bar on it, while larger amounts of data is retrieved by the QueryResultIterator but I can't find out when exactly the asynchronous QueryResultIterator finishes. So I also don't know when the pop-up window can be removed. Any suggestions??

Thanks and best regards,
Henry
Hi,

We had implemented some extra functionality into the last version of the Email Agent and since our customers want to have the large attachment handling we decided to implement these functionalities into the new version too. So I started with a retrieve call and was really surprised to find out that the SObject class used in the new Email Agent does not support the get_any() method. That means theres no way to get the returned data from the retrieve API call, at least no documented way. Even the API 8.0 documentation examples use get_any so what was the reason to leave it out?

As a workaround I tried use WSDL2Java with the partner.wsdl file that was located in the Email Agent's root folder, but the output didn't match the contents of the partnerWSDL.jar. What also confused me was the fact that the EmailAgent doesn't use Axis anymore, but Axis is still required if you create the binding stub the old way.

So please, could anybody explain what happened to Email Agent and how standard webservice calls can be implemented?

Thanks in advance,
Henry
Hi,

I'm still using the PEAR SOAP libraries and never had problems creating SObjects like tasks. But now we moved to a new ISP and after all create calls the XML response seems to be invalid an I get the following error message:

XML error on line 1 col 4 byte 4 not well-formed (invalid token)

When I print out the resulting error object it shows that the sObject was created but the positive xml response seems to cause the mentioned error.

I already tried to set the default character set to utf-8 using PHP's ini_set and Apache's .htaccess directives but that didn't change anything.

Since this is a massive problem for a customer of ours any help is greatly appreciated!

Thanks,

Henry

I have just created an Apex Class that implements the InstallHandler interface, and have associated it with a managed package. However, when I install my package, the SObject.put(SObjectField f, Object value) are throwing a "Field is not editable" SObjectException. I found this strange, since the error is being thrown before I even do DML --- i.e. the actual put() call is throwing the error. I thought this must be a Field-Level Security issue, so I made sure that the System Admin profile (both in my package development org, and in the org into which I am installing my package) has read/write access to the field in question. But I still get the error.

 

Digging deeper, I did some debug output  in my install script on the Schema information for the field in question and sent it to myself in an email. To my surprise, the field was not even accessible, much less editable! I then checked accessibility of the object. Again, isAccessible() returned FALSE! So I checked some other objects --- same thing. Contact, Account, Contact.LastName, Account.Name --- isAccessible() for all of these fields/objects returns FALSE. 

 

Am I missing something? Is this just a bug in the Schema information? Or do InstallHandlers really not have access to any objects/fields? This can't be possible.

 

here is the code:

 

global abstract class InstallScript implements InstallHandler {

	// The module that we will be installing
	protected String moduleName;

	// Set the name of the module associated with this package install 
	global abstract void setModule();
	
	// Any additional on install logic should be defined in this method
	global abstract void onInstallLogic(InstallContext ctx);

	global void onInstall(InstallContext ctx) {
		// Set the module that we are running in
		setModule();
		
		if (moduleName != null) {
			
			// See if a StaticResource containing new pages for this module yet exists
			StaticResource sr;
			try {
				sr = [select Id, Body, Name, NamespacePrefix from StaticResource where Name = :(moduleName + 'Pages')];
			} catch (Exception ex) {
				// No pages exist for this module
			}
			if (sr != null) {
				String username,profileId,accessible,createable,updateable,localname,name,body,debugString;
				DescribeFieldResult dfr;
				SObjectField f;
				try {
					username = UserInfo.getUserName();
					profileId = UserInfo.getProfileId();
					f = Page__c.Layout__c;
					dfr = f.getDescribe();
					accessible = dfr.isAccessible() + '';
					createable = dfr.isCreateable() + '';
					updateable = dfr.isUpdateable() + '';
					localname = dfr.getLocalName();
					name = dfr.getName();
					body = sr.Body.toString();
					
					debugString = 
						'Username: ' + ((username != null) ? username : 'null') 
						+ 'ProfileId: ' + ((profileId != null) ? profileId : 'null')
						+ ', Contact.Accessible: ' + Contact.SObjectType.getDescribe().isAccessible()
						+ ', Contact.LastName.Accessible: ' + Contact.LastName.getDescribe().isAccessible()
						+ ', Page__c.Accessible: ' + Page__c.SObjectType.getDescribe().isAccessible()
						+ ', Page__c.Name.Accessible: ' + Page__c.Name.getDescribe().isAccessible()
						+ ', Layout__c.Accessible: ' + accessible
						+ ', Layout__c.Createable: ' + createable
						+ ', Layout__c.Updateable: ' + updateable
						+ ', Layout__c.getLocalName: ' + localname
						+ ', Layout__c.getName: ' + name
						+ ', body: ' + body;
                               } catch (Exception ex) {

                                    // Send email
                               }
                         }
                   }
             }
}

The actual InstallScript is a simple implementation of the abstract class. The important thing to note is that all of the isAccessible() calls are returning FALSE.

 

I received the same results in both API versions 24 and 25.

 

Any ideas?

 

Zach McElrath

Skoodat LLC

Hi,

 

I'd like to use HTTP classes to load an image from the web then save it as an Attachment and finally send it attached to an email. At first glance everything seems to work fine. But the picture I receive is obviously a corrupt file. Any ideas what's wrong with my code:

 

 

public class EmailTestCtr {
	
	public Integer totalFileSize {get; set;}
	public Email__c mail {get; set;}
	public String contentType {get; set;}
	public String response {get; set;}
	
	public EmailTestCtr(){
		totalFileSize = 0;
	}
	
	public void loadFile(){
		String url = '';
		
		Http h = new Http();
		HTTPRequest req = new HttpRequest();
        
        req.setEndpoint('http://www.clienthouse.com/images/f106e78f34/CH_location_web1.jpg');
        req.setMethod('GET');
        req.setCompressed(false);
		
		HTTPResponse resp = h.send(req);
		this.contentType = resp.getHeader('Content-Type');
		this.response = resp.getHeader('Content-Length');
		
		System.debug(resp.getBody());
		String body = resp.getBody();
		
		Attachment a = new Attachment();
		try {		
			if(this.mail == null){
				mail = new Email__c(
					Name = 'test'
				);
				insert mail;
			}
			
			a.Body = Blob.valueOf(body);
			a.Name = 'Name';
			a.ParentId = mail.Id;
			a.ContentType = this.contentType;
			insert a;
		} catch(DMLException e){
			ApexPages.addMessages(e);
		}
		
		this.totalFileSize += [select BodyLength from Attachment where Id = :a.Id].BodyLength;
		
	}
	
	public void sendEmail(){
		
		Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
		String[] toAddresses = new String[] {'h.hess@clienthouse.com'};
		email.setToAddresses(toAddresses);
		email.setSubject(this.mail.Name);
		email.setPlainTextBody('Text goes here.');
		List<Messaging.EmailFileAttachment> files = new List<Messaging.EmailFileAttachment>();
		for(Attachment file : [select Name, Body, ContentType from Attachment where ParentId = :this.mail.Id]){
			System.debug('------------>FILE' + file);
			Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
			efa.setBody(file.Body);
			efa.setContentType(file.ContentType);
			efa.setFileName(file.Name + '.jpg');
			files.add(efa);
		}
		email.setFileAttachments(files);
		
		Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
		
	}
	
}

 

 

Thanks and best regards,

Henry

Hi,

 

We tried to implement a single sign on mechanism of a third party web solution using the Crypto.encrypt method. The third party solution requires that the initialization vector is XOR encoded into the first 16 bytes of the transmitted SSO Token. In java this would be done like this:

 

 

for (int i = 0; i < 16; i++) {
   data[i] ^= INIT_VECTOR[i];
}

 

 

where data and INIT_VECTOR would be byte arrays. In Apex there's nothing like a byte array and Blob has no methods at all. The XOR operator ^ does exist in Apex but it can only be used with Boolean expressions and Integers. So I can't just use the Strings and do some wild XOR character operations. Does anybody know how I can implement an XOR encryption like in Java or any other programming language using Apex?

 

Thanks for your help and best regards,

Henry

How do I query for all the list view names and ids for a specific sObject via apex?

 

I don't see this in the API or as a describe object option.

 

Thanks,

 

Matt

Hi all,

 

I have some questions regarding basic features I would have expected in Visualforce/Apex:

 

  • How do you determine which record types are available for the current user?
    A list of all available record types for a certain object is pretty useless if you don't know which are atually available for which profile.
  • How do you find out which picklist values a user may see depending on the record type of the current record?
    Again, a list of all available picklist value is usless unless I do not know which of them may be displayed to the current user.

Especially in salesforce instances with lots of record types and record type dependent picklists, it's essential to follow the existing configuration in Visualforce pages / controllers. So any suggestions or workarounds are greatly appreciated.

 

Thanks and best regards,

Henry

 

 

 

Hi  -

 

I have a page with several fields on it. We are using the translation work bench to translate all the fields. Thus I don't want to hardcode in the field labels because I want them to appear in the users native language.  Below is a code segement I wrote to describe the object, and get the field labels. It works, but the next page I have to do this to has 150 fields, and I really would like to find a better way to do this. I am open to any suggetions. 

 

 

for (var i = 0; i < mdfObj.fields.length; i++){ if(mdfObj.fields[i].name == 'Channel_Account_Manager__c') camNameLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Channel_Account_Manager_Title__c') camTitleLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Channel_Account_Manager_Email__c') camEmailLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Channel_Account_Manager_Phone__c') camPhoneLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Channel_Account_Manager_Mobile_formula__c') camMobileLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager__c') iCamNameLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager_Title__c') iCamTitleLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager_Email__c') iCamEmailLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager_Phone__c') iCamPhoneLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager_Mobile__c') iCamMobileLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager__c') mpmNameLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager_Title__c') mpmTitleLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager_Email__c') mpmEmailLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager_Phone__c') mpmPhoneLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager_Mobile__c') mpmMobileLabel = mdfObj.fields[i].label; }

 

 

 

Hi everybody,

I'd like to know if it's possible to call an Apex based Webservice method using a standard outbound message?
Seems to be an odd idea at first glance but we have some use cases/situations that would require a minor delay in processing, like a webservice call, and that can not be realised using triggers. So did anybody manage to do this??

Thanks and best regards,
Henry
Hi everybody,
I'm working on an SControl that displays a special printable view including the last five Activities of an Account. The Activity object seems pretty helpful since it combines Event and Task data, the only thing that seems to be missing is a field where the Time of an Event is stored. The Duration is available but does it make any sense without the start time of the Event? So it would be great if you could tell me where to find the time of an Event in the Activity History object.

Thanks and best regards,
Henry

Can we use Apex Email Services as similar to Email to Case? Is it possible? I do have around 10 routing address in Email to case, can I achieve same by Apex email services. Is it possible to rename Salesforce generated domain name is email services.

 I didn’t find any detailed documentation regarding this. Any detailed clarifications highly appreciated.

 Thanks ~ Nazeer

  • November 16, 2007
  • Like
  • 0
Hello everybody,

I'd like to display a pop-up window with a progress bar on it, while larger amounts of data is retrieved by the QueryResultIterator but I can't find out when exactly the asynchronous QueryResultIterator finishes. So I also don't know when the pop-up window can be removed. Any suggestions??

Thanks and best regards,
Henry
Hi,

We had implemented some extra functionality into the last version of the Email Agent and since our customers want to have the large attachment handling we decided to implement these functionalities into the new version too. So I started with a retrieve call and was really surprised to find out that the SObject class used in the new Email Agent does not support the get_any() method. That means theres no way to get the returned data from the retrieve API call, at least no documented way. Even the API 8.0 documentation examples use get_any so what was the reason to leave it out?

As a workaround I tried use WSDL2Java with the partner.wsdl file that was located in the Email Agent's root folder, but the output didn't match the contents of the partnerWSDL.jar. What also confused me was the fact that the EmailAgent doesn't use Axis anymore, but Axis is still required if you create the binding stub the old way.

So please, could anybody explain what happened to Email Agent and how standard webservice calls can be implemented?

Thanks in advance,
Henry
    We are using imaps as a mail server. When we ran email2case.bat, we got the following error message:

Message: sun.security.validator.ValidatorException: No trusted certificate found;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found


We have a SSL certification and add the following option to the java command.

 -Djavax.net.ssl.trustStore=/home/EmailAgent60/.keystore

Anyone can run emal2case.bat with imaps successfully?