• EchoEcho
  • NEWBIE
  • 30 Points
  • Member since 2009

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 14
    Replies

With the Blackberry application you could change to plain text and the SFDC application would open if you were sent a link via email.  Basically we want our sales reps to get a notification of their leads immediately and do a few items.. They are fairly simple just that the web page on the iPhone is a bit small would be much easier if it opened the app.  Anyone been able to do this? 

 

Thank you!

Posted this the other day on how to download images from the Chatter API using XMLHttpRequest2, which is available on iOS 5 and Android OS 3.0:

 

http://www.modelmetrics.com/tomgersic/using-xmlhttprequest2-in-ios-5-to-download-binary-files-using-html5phonegap/

 

If you wanted to modify forcetk to do this easily, here's the code:

 

    /**
     * Utility function to query the Chatter API and download a file
     * @param path resource path relative to /services/data
     * @param mimetype of the file
     * @param callback function to which response will be passed
     * @param [error=null] function to which request will be passed in case of error
     * @param rety true if we've already tried refresh token flow once
     **/
    forcetk.Client.prototype.getChatterFile = function(path,mimeType,callback,error,retry) {
        var that = this;
    
        var url = this.instanceUrl + path;

        var request = new XMLHttpRequest();
        
                
        request.open("GET", url, true);
        request.responseType = "arraybuffer";
        
        request.setRequestHeader(that.authzHeader, "OAuth " + that.sessionId);
        request.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + that.apiVersion);
        
        request.onreadystatechange = function() {
            // continue if the process is completed
            if (request.readyState == 4) {
                // continue only if HTTP status is "OK"
                if (request.status == 200) {
                    try {
                        // retrieve the response
                        callback(request.response);
                    }
                    catch(e) {
                        // display error message
                        alert("Error reading the response: " + e.toString());
                    }
                }
                //refresh token in 401
                else if(request.status == 401 && !retry) {
                    that.refreshAccessToken(function(oauthResponse) {
                        that.setSessionToken(oauthResponse.access_token, null,oauthResponse.instance_url);
                        that.getChatterFile(path, mimeType, callback, error, true);
                    },
                    error);
                } 
                else {
                    // display status message
                    error(request,request.statusText,request.response);
                }
            }            
            
        }

        request.send();
        
    }

 

Wondering if anybody has figured out a way to do this...

 

From what I can tell, right now, the only way to specify an attached image in an email from Apex is to use setInline(true) on an EmailFileAttachment, and this generates a "Content-Disposition: inline" header in the email which is promptly ignored by pretty much every email client. Giving the ability to set a Content-ID header would allow the developer to embed an attached image into the body of an email.

 

 

For instance, this Content-ID is an example from Gmail:
Content-ID: <ii_12e92eb7a7875474>

 

 

 

It can be referenced in the html body of the email with:

<img src="cid:ii_12e92eb7a7875474">

 

 

Is this possible in Apex at all?

 

Thanks,

Tom

 

Just posted this example of using Amazon Simple Email Service from Force.com:

 

http://www.modelmetrics.com/general/cloud-to-cloud-using-aws-simple-email-service-from-force-com/

 

Includes code samples and such to get you up and running.

 

Tom

I have a Global class exposed as a webservice that is called by users who do not have the "Add Content" Workspace Permission, and am using "without sharing" to try to make it possible for that class to update fields on Content records. However, when I try to call the methods in this class, I receive insufficient access exceptions:

 

12:18:32.091|EXCEPTION_THROWN|[23]|System.DmlException: Update failed. First exception on row 0 with id 068M00000004G5HIAU; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

 

If I try the same thing with a user that does have the "Add Content" workspace permission, everything works as expected. Is it possible to have a method run in the system context when updating content records?

 

Thanks,

Tom

Hi,

 

I'm trying to write unit tests for Content. It seems that it is impossible to create a Workspace record in Apex, so I guess we have to use an existing one in the org?

 

Bigger question: If I create a Content record, relate it to an existing workspace using FirstPublishLocationId, and insert it, and then try to make an update to that Content record, I get this error:

 

Document with ID: 06930000000YPbp already has an owning Workspace

 

I get the same error whether or not this is in a test class. If I do it outside of a test class, and just use the record Id a few seconds later to do my update, it will work. So, it seems to be time-based... Is it not possible to update a newly created Content record from within a test class?

 

Thanks,

Tom

I'm scoping out the possibility of doing a mass email from Apex. The mass email limits for Unlimited Edition of SFDC is 1000 external email addresses per email. However, the Apex docs specify a blanket limit of 250 email addresses per email. Is this accurate, or does it depend on the edition of SFDC I'm using?

 

Thanks,

Tom

Hi All,

 

On the home page for Customer Portal, there is a Tasks list, which seems to suggest that it must be possible to assign tasks to Customer Portal users. However, when I actually try to do so, it won't let me pick any Customer Portal users in the assignment field. How does one assign a task to a Customer Portal user?

 

Thanks,

Tom

I have a Sites page that dynamically generates a PDF from a custom CMS. As part of that page, I would like to dynamically include certain images throughout, accessed from Static Resources, in sections of HTML generated by the Apex Controller through the use of <apex:outputText value="{!someGetter}" escape="false" />.

 

If the page is not set to renderAs="pdf", I can access Static Resource images in the return value of the Apex method like this:

 

return '<img src="resource/ResourceName">';

 

However, if I set renderAs="pdf" so that the page renders as PDF, the images show up broken. I've tried a few different ways of accessing the Static Resource, including the full URL, as well as linking to images off-site, like the Google Logo. I've even tried embedding the image into the text, using Base64. It seems like the only way to include an image in a PDF is to have it directly in the VisualForce page, which is inconsistent with the rendering of a regular VF page. Is this a bug, or is there some way to accomplish what I'm trying to do here?

 

Thanks,

Tom

Is it possible to "create" a Site instance to use in test methods? I have a controller that does slightly different things depending on which Site is accessing it, but Site.getName() is always null in my test methods. It doesn't seem to be possible to do a Site newSite = new Site(), so what is the correct way to do this?

 

Thanks,

Tom

Hi All,

 

I'm having some very strange problems with SOQL and Collection limits in a VF Controller, but not immediately... sort of cumulatively... or at least after awhile...

 

First off, there's no possible way that there are enough records in the objects that I'm dealing with to go over the 100 query SOQL limit or the 1000 row Collection limit. And yet, at first, I was getting this error:

 

System.Exception: Too many SOQL queries: 101

 

But like I said, not immediately. The class works fine when I test it, and when I deploy it. It will continue to work fine for the next 8 hours or so, while a number of people are happily using it with no problem. And then out of nowhere, I'll get an exception email. So I go look at the VF page, and I get the same error. I've found, after some experimentation, that all I have to do is make some small modification to the controller, like adding a space after a line. I can then re-deploy the class (with no changes made), and the exception will go away for another 8 hours or so.

 

So, I decided to rewrite the class so that there would be no way for this query to get called more than 100 times. Aha! I figured... problem solved. But 8 hours later, I get this email:

 

System.Exception: collection exceeds maximum size: 1001

 

Again, there's no way. There aren't 1001 records in any of these objects. There's like 20 rows getting returned, at most. So, I add a space to the end of a line in the controller, re-deploy, and voila, problem solved. Until tomorrow, at least.

 

Does anybody have any idea what's going on here? Any logical explanation for this? Help?

 

Here's the controller code, if that's helpful at all... this is the second version that I changed so as to avoid getting the first exception. The collection that it's complaining about is List<PhysicianWrapper> physicians.

 

 

public class Customer_Survey_Controller
{
//used for javascript communication
public String selectedPhysiciansString {get; set;}

//the physicians the user has to choose from. Limited by physicians for whom we already have a previous baseline survey.
public List<PhysicianWrapper> availablePhysicians
{
get
{
//generate a list of physician IDs for whom we have a baseline survey
List<PhysicianWrapper> physicians = new List<PhysicianWrapper>();

String idList = '';
Set<String> accountIds = new Set<String>();

for(Contact physicianRecord : [SELECT Id, Name, Account.Id, Account.Name FROM Contact WHERE Id in (SELECT Physician__c FROM Surveys__c) AND Experience_Level__c = 'Experienced Injector' ORDER BY Name])
{
if(physicianRecord.Id != null && physicianRecord.Name != null)
{
//make sure we have no duplicates...
if(physicians.size() == 0 || (physicians.get(physicians.size()-1).physicianRecord.Id != physicianRecord.Id))
{
PhysicianWrapper physicianWrapper = new PhysicianWrapper();
physicianWrapper.physicianRecord = physicianRecord;
physicianWrapper.supportStaff = new List<selectOption>(); //supportStaff(physicianRecord.Account.Id,physicianRecord.Id);
physicians.add(physicianWrapper);

accountIds.add(physicianRecord.Account.Id);
}
}
}

//get the support staff...

for(String accountId : accountIds)
{
idList += '\''+accountId+'\',';
}
idList = idList.substring(0,idList.length()-1);

List<Contact> supportStaffRecords = Database.query('SELECT Id, Name, Role__c, AccountId FROM Contact WHERE AccountId IN ('+idList+') AND Email <> \'\' ORDER BY Name asc');

for(Integer i=0; i<physicians.size();i++)
{
for(Integer j=0; j<supportStaffRecords.size(); j++)
{
if(physicians[i].physicianRecord.Account.Id == supportStaffRecords[j].AccountId)
{
//checkbox id contains both the support staff Id and the pseudo-parent physician Id
//we will send the email to the support staff member, but assign the survey record to the physician
//support.add(new selectOption(supportStaffRecord.Id+','+physicianId,supportStaffRecord.Name));
if(supportStaffRecords[j].Role__c != null)
physicians[i].supportStaff.add(new selectOption('surveyBox,'+supportStaffRecords[j].Id+','+physicians[i].physicianRecord.Id, supportStaffRecords[j].Name+' ('+supportStaffRecords[j].Role__c+')'));
else
physicians[i].supportStaff.add(new selectOption('surveyBox,'+supportStaffRecords[j].Id+','+physicians[i].physicianRecord.Id, supportStaffRecords[j].Name));

}
}
}

return physicians;
}
set;
}

//wrapper class to pass display data to the VF page
class PhysicianWrapper
{
public Contact physicianRecord {get; set;}
public List<selectOption> supportStaff {get; set;}
}

}

 

 

 

 

 

 

Thanks,

Tom 

Message Edited by EchoEcho on 06-03-2009 03:25 PM
Message Edited by EchoEcho on 06-03-2009 03:28 PM

Is it possible to use a Visualforce Email Template to send an email to one person, while including some information from the Contact record of a secon person? For instance, I use setTargetObjectId() to pull in the email recipient's name, and I wanted to use setWhatId() to pass in an ID for a second contact, but setWhatId won't accept an ID of type Contact.

 

Thanks,

Tom

I'm trying to create a Task from Apex for the current logged in user. It seems simple enough, and I'm doing pretty much exactly what is specified in the Developer Guide:

 

                 //create a task for the user
                //Task newTask = new Task(Subject='Complete Survey for Transaction');
                Task newTask = new Task(Description = 'Survey Transaction',
                                        Priority = 'Normal',
                                        Status = 'Inbound Email',
                                        Subject = 'Other',
                                        IsReminderSet = true,
                                        ReminderDateTime = System.now()+1,
                                        WhoId = userContact[0].ContactId    );             
                insert newTask;

 

But I keep getting this exception:

 

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Free-form text is not allowed for the Subject field. Please select a pre-determined value from the picklist.: [Subject]

 

The subject that I've specified ('Other') is in the Task subject picklist, and Task.Subject is supposed to be a String, so I don't know what else I'm supposed to do to get it to match up my subject with the pre-determined values...

 

Anybody happen to know?

 

Thanks,

Tom 

Hi,

 

I'm trying to write unit tests for Content. It seems that it is impossible to create a Workspace record in Apex, so I guess we have to use an existing one in the org?

 

Bigger question: If I create a Content record, relate it to an existing workspace using FirstPublishLocationId, and insert it, and then try to make an update to that Content record, I get this error:

 

Document with ID: 06930000000YPbp already has an owning Workspace

 

I get the same error whether or not this is in a test class. If I do it outside of a test class, and just use the record Id a few seconds later to do my update, it will work. So, it seems to be time-based... Is it not possible to update a newly created Content record from within a test class?

 

Thanks,

Tom

Posted this the other day on how to download images from the Chatter API using XMLHttpRequest2, which is available on iOS 5 and Android OS 3.0:

 

http://www.modelmetrics.com/tomgersic/using-xmlhttprequest2-in-ios-5-to-download-binary-files-using-html5phonegap/

 

If you wanted to modify forcetk to do this easily, here's the code:

 

    /**
     * Utility function to query the Chatter API and download a file
     * @param path resource path relative to /services/data
     * @param mimetype of the file
     * @param callback function to which response will be passed
     * @param [error=null] function to which request will be passed in case of error
     * @param rety true if we've already tried refresh token flow once
     **/
    forcetk.Client.prototype.getChatterFile = function(path,mimeType,callback,error,retry) {
        var that = this;
    
        var url = this.instanceUrl + path;

        var request = new XMLHttpRequest();
        
                
        request.open("GET", url, true);
        request.responseType = "arraybuffer";
        
        request.setRequestHeader(that.authzHeader, "OAuth " + that.sessionId);
        request.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + that.apiVersion);
        
        request.onreadystatechange = function() {
            // continue if the process is completed
            if (request.readyState == 4) {
                // continue only if HTTP status is "OK"
                if (request.status == 200) {
                    try {
                        // retrieve the response
                        callback(request.response);
                    }
                    catch(e) {
                        // display error message
                        alert("Error reading the response: " + e.toString());
                    }
                }
                //refresh token in 401
                else if(request.status == 401 && !retry) {
                    that.refreshAccessToken(function(oauthResponse) {
                        that.setSessionToken(oauthResponse.access_token, null,oauthResponse.instance_url);
                        that.getChatterFile(path, mimeType, callback, error, true);
                    },
                    error);
                } 
                else {
                    // display status message
                    error(request,request.statusText,request.response);
                }
            }            
            
        }

        request.send();
        
    }

 

With the Blackberry application you could change to plain text and the SFDC application would open if you were sent a link via email.  Basically we want our sales reps to get a notification of their leads immediately and do a few items.. They are fairly simple just that the web page on the iPhone is a bit small would be much easier if it opened the app.  Anyone been able to do this? 

 

Thank you!

I have a Global class exposed as a webservice that is called by users who do not have the "Add Content" Workspace Permission, and am using "without sharing" to try to make it possible for that class to update fields on Content records. However, when I try to call the methods in this class, I receive insufficient access exceptions:

 

12:18:32.091|EXCEPTION_THROWN|[23]|System.DmlException: Update failed. First exception on row 0 with id 068M00000004G5HIAU; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

 

If I try the same thing with a user that does have the "Add Content" workspace permission, everything works as expected. Is it possible to have a method run in the system context when updating content records?

 

Thanks,

Tom

Hi,

 

I'm trying to write unit tests for Content. It seems that it is impossible to create a Workspace record in Apex, so I guess we have to use an existing one in the org?

 

Bigger question: If I create a Content record, relate it to an existing workspace using FirstPublishLocationId, and insert it, and then try to make an update to that Content record, I get this error:

 

Document with ID: 06930000000YPbp already has an owning Workspace

 

I get the same error whether or not this is in a test class. If I do it outside of a test class, and just use the record Id a few seconds later to do my update, it will work. So, it seems to be time-based... Is it not possible to update a newly created Content record from within a test class?

 

Thanks,

Tom

I have a Sites page that dynamically generates a PDF from a custom CMS. As part of that page, I would like to dynamically include certain images throughout, accessed from Static Resources, in sections of HTML generated by the Apex Controller through the use of <apex:outputText value="{!someGetter}" escape="false" />.

 

If the page is not set to renderAs="pdf", I can access Static Resource images in the return value of the Apex method like this:

 

return '<img src="resource/ResourceName">';

 

However, if I set renderAs="pdf" so that the page renders as PDF, the images show up broken. I've tried a few different ways of accessing the Static Resource, including the full URL, as well as linking to images off-site, like the Google Logo. I've even tried embedding the image into the text, using Base64. It seems like the only way to include an image in a PDF is to have it directly in the VisualForce page, which is inconsistent with the rendering of a regular VF page. Is this a bug, or is there some way to accomplish what I'm trying to do here?

 

Thanks,

Tom

Is it possible to "create" a Site instance to use in test methods? I have a controller that does slightly different things depending on which Site is accessing it, but Site.getName() is always null in my test methods. It doesn't seem to be possible to do a Site newSite = new Site(), so what is the correct way to do this?

 

Thanks,

Tom

There are a few required fields in both standard objects and custom objects that I would like to pre-populate when they are created so that the user doesn't feel compelled to fill them in (since they are required).  What I'm talking about is having the data in the field box before the user clicks "save".  I know I can do this after the user clicks "save" (and that is what I'm already doing), but I want the fields filled as soon as the user sees the blank form.

 

Alternatively, is there a way I can make an exception to hide required fields that a trigger will populate before insert?

I'm trying to create a Task from Apex for the current logged in user. It seems simple enough, and I'm doing pretty much exactly what is specified in the Developer Guide:

 

                 //create a task for the user
                //Task newTask = new Task(Subject='Complete Survey for Transaction');
                Task newTask = new Task(Description = 'Survey Transaction',
                                        Priority = 'Normal',
                                        Status = 'Inbound Email',
                                        Subject = 'Other',
                                        IsReminderSet = true,
                                        ReminderDateTime = System.now()+1,
                                        WhoId = userContact[0].ContactId    );             
                insert newTask;

 

But I keep getting this exception:

 

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Free-form text is not allowed for the Subject field. Please select a pre-determined value from the picklist.: [Subject]

 

The subject that I've specified ('Other') is in the Task subject picklist, and Task.Subject is supposed to be a String, so I don't know what else I'm supposed to do to get it to match up my subject with the pre-determined values...

 

Anybody happen to know?

 

Thanks,

Tom 

I am not able to save using the default rich text editor:

I am trying to use:

Code:
<apex:inputtextarea id="editor" rows="10" style="width:100%;" value="{!Object_Name__c.html_source__c}" richtext="true"/>

 If I take out the richtext="true" and use
Code:
<apex:inputtextarea id="editor" rows="10" style="width:100%;" value="{!Object_Name__c.html_source__c}"/>

It works fine.

Thanks,
Chris
 





Message Edited by ldChris on 01-19-2009 03:52 PM
I have a visualforce email template which looks like so:



<messaging:emailTemplate subject="A High Touch record has been assigned to you" recipientType="User" relatedToType="Touch__c">
<messaging:plainTextEmailBody>

The following High Touch record has been assigned to you.

{!recipient.Name}
Account: {!relatedTo.Account__c}
Type: {!relatedTo.Type__c}
Contact Name: {!relatedTo.Contact_Name__c}
Contact Phone: {!relatedTo.Contact_Phone__c}
Contact Email: {!relatedTo.Contact_Email__c}
Company News: {!relatedTo.Company_News__c}
Notes: {!relatedTo.Notes__c}

</messaging:plainTextEmailBody>
</messaging:emailTemplate>


I want to add a link back to view the custom object record but cannot figure out what to use.

I tried {!Touch__c.Link} (among many other things) but this does not work. Any suggestions?