Paul’s Salesforce Blog

What’s new with Salesforce?

Mahmood’s Steps for Migrating Attachments to Content

Posted by paulovery on March 2, 2019

Taken from here: https://salesforce.stackexchange.com/questions/122301/migrate-attachments-to-salesforce-files

Migration – from Attachment to Salesforce Files

After a lot of RnD, came up with the following:

  1. Export Attachments data using data loader.
  2. Export Attachment files, using data export wizard or File exporter.
  3. Create two fields, ParentId and AttachmentId on ContentVersion object
    • ParentId will hold the id of the entity, attachment was linked to.
    • AttachmentID (with unique constraint) will hold the id of the attachment from attachment object.
  4. Create a CSV, ContentVersion_upload.csv, for ContentVersion with the following fields
    • Attachment_id (AttachmentId from file exported in step-1)
    • ISDELETED
    • PARENTID (Entity Id of the object, from file exported in step 1)
    • Versiondata (local file path)
    • PathOnClient (local file path)
    • Title (title of the file)
    • OWNERID
    • DESCRIPTION
  5. Upload (Insert) ContentVersion.csv.
  6. Export ContentVersion data uploaded in step-5.
  7. Create another CSV for ContentDocumentLink (and update ContentDocumentID and ParentEntityId, from the ContentVersion file exported in step-5) with the following fields:
    • CONTENTDOCUMENTID (ContentDocumentId from file exported in step-6)
    • LINKEDENTITYID (ParentId from file exported in step-6)
    • SHARETYPE
    • VISIBILITY
  8. Upload (Insert) ContentDocumentLink.

I, also, migrated legacy notes to Enhanced Notes . For a complete tutorial on migration of both Notes & Attachments to Files and Enhanced notes please refer to this blog that I created.

Thanks, Mahmood!

Posted in Uncategorized | Leave a Comment »

Want to know an Object Type from an ID?

Posted by paulovery on November 20, 2015

Here’s how to do it in Salesforce APEX:

ID thisId = someId;
Schema.SObjectType objType = thisId.getSObjectType();

That’s it!  objType can now be used to identify the object type.

You can do comparisons with objType like this:

if (objType == ‘Quote’)….

or

if (objType == Quote.sObjectType)…

I hope you find this helpful!

Posted in Uncategorized | Leave a Comment »

Correct format of a DateTime string in a SOQL statement

Posted by paulovery on June 29, 2015

Once in awhile I need to do a query against a DateTime string.  Since it’s so hard to remember the correct format, I decided to share it here.

Here is the correct format for a query with the DateTime included:

SELECT id FROM Account WHERE lastmodifieddate > 2015-05-20T00:00:00Z

Posted in Uncategorized | Leave a Comment »

Salesforce Webinars

Posted by paulovery on March 5, 2014

Ever miss a Salesforce Webinar that you wanted to see?

Maybe you watched one, but would like to view it again?

 

You can view Salesforce’s Webinars at this url:

http://developer.force.com/content/type/Webinar

 

Enjoy!

Posted in Uncategorized | Leave a Comment »

Retrieve Picklist Values from a Salesforce Field

Posted by paulovery on March 2, 2014

In many cases, when you want to display an Object’s picklist, you can just use APEX:outputField on your Visualforce page.  In some cases, though, you may not be able to use APEX:outputField, resulting in an HTML SELECT object which has to be modified every time the picklist choices are changed.

The solution?   Extract the picklist values from the object for use on your Visualforce page!

This APEX code will allow your administrator to add picklist entries to a field, without requiring corresponding changes to the Visualforce Page.  The example shows how to retrieve the picklist values, and it adds them to a SelectOption list, but you should be able to modify the code to meet your own needs.

private void setPicklistOptions(){
// Retrieve the picklist values
Schema.DescribeFieldResult dfr = CustomObject__c.PicklistField__c.getDescribe();
List<Schema.PicklistEntry> picklistEntries = dfr.getPicklistValues();

// Add picklist values to a SelectOption list
productsSelect = new List<SelectOption>();
productsSelect.add(new SelectOption(‘All’, ‘All’));
for (Schema.PicklistEntry ple : picklistEntries){
productsSelect.add(new SelectOption(ple.getValue(), ple.getValue()));
}
}

Hope you find this useful!

Posted in Salesforce Development | 2 Comments »

Import Object Data Directly into a Map

Posted by paulovery on January 29, 2014

Here’s a neat trick that I found.  You can use it to import object data directly into a Map, indexed by the Object’s ID.

Here is an example:

Map<ID,Contact> contactMap = new Map<ID,Contact>([select id, name, phone, email from contact]);

 

This will import the results of the SOQL query directly into the Map!

 

I hope you find this as useful as I do.

Posted in Salesforce Development | Tagged: , | 1 Comment »

Salesforce NHUG Newsletter

Posted by paulovery on November 24, 2009

 

Hello New Hampshire User Group Members,

Dreamforce

I made it back from Dreamforce @ San Francisco safely.  It was a lot of fun and very educational, too.  If you weren’t able to make it, you can still experience some of the event online.  You can see the Keynote speeches by going here or here.

The big announcement of the week was the new Salesforce Collaboration Cloud called Chatter.  This cloud will allow you to have a facebook/twitter – like collaboration within your organization.  You can follow objects or people in your org, allowing you to see any events that affect those people or objects.  During the Opening Keynote, Salesforce Co-founder Parker Harris said to Marc Benioff: “Your apps are talking”.  Visit the Chatter Web Page to view a demo of this new Cloud.

If you attended Dreamforce and would like to download content, you can do so at the Attendee Portal by clicking the Content link on the left.

Even if you didn’t attend Dreamforce, you can view Breakout Sessions on You Tube.

New Salesforce Materials

Salesforce has released 3 documents in the past week.  These documents are:
–  The new release of the Force.com Cookbook
Force.com Fundamentals, An Introcution to custom application development in the cloud
The Force.com Workbook, quick 30 minute tutorials to build your first app in the cloud

Odds and Ends

Check out the latest User Experience Blog entry, which talks about the new Graphical Approval Process Editor.

If you’re running a Non-Profit on Salesforce?  You might be interested in Model Metrics’ free application for Donation Management.

Here’s a nice little blog entry which provides a piece of trigger code that counts how many times an Opportunity date has been pushed out.

Doing some Web Development?  Here are 34 Cheat Sheets that you might find helpful.

The next NHUG Meeting?

JP and I have yet to pick a date for our next meeting, or to put together a list of presenters.  If you are interested in presenting or know of a product or feature that you’d like to see presented, then please let us know.  As soon as we know more about the next meeting, we’ll let you know.

Take care,
Paul Overy
NHUG Co-Leader

Posted in Salesforce General | Leave a Comment »

New Releases of Force.com Cookbook and Force.com Fundamentals

Posted by paulovery on November 22, 2009

Salesforce.com has released new versions of both the Force.com Cookbook and Force.com Fundamentals.  Blog entries can be found on the Salesforce Community site at the links, below.

Force.com Cookbook Blog Entry

Force.com Fundamentals Blog Entry

You can download a .pdf version of these documents if you have a developer account.  Developer accounts are available for free by clicking the “Join Now” link at the top of either of the blog pages listed.

Posted in Salesforce Development | Leave a Comment »

Watch Force.com Developer Courses on iTunes!

Posted by paulovery on September 1, 2009

Great news!  Salesforce.com has made their developer courses available on iTunes!

To see their blog post, follow this link:

http://blog.sforce.com/sforce/2009/08/watch-forcecom-developer-courses-on-itunes.html

Posted in Salesforce Development | Leave a Comment »

Formatting Time in APEX

Posted by paulovery on August 27, 2009

Every time I need to display the date and time someplace, I have to go digging through old code to find examples of how I’ve formatted  it in the past.  When I encountered this problem today,  I decided to post a blog on it.  In the future I’ll be able to come here to see how to do it, and hopefully others will benefit from it, as well:

So here’s the goal of this blog:  I simply want to create a string that displays the current time & date in some readable format, such as: Aug 26, 2009 02:45 AM.  This is actually quite easy to do, once you know how to retrieve the time and what the formatting characters are to display it properly.

Getting the current time is easy since there is a simple function that returns the current time into a DateTime variable:  datetime.now()

So that leaves formatting the result, which is the part that is difficult to memorize if you don’t use it frequently.  Formatting requires that you provide a character sequence that defines what the string-formatted version of the date/time will look like.  For example, to format a string to look like this: 08-26-09 02:45 AM, you would use a format string that looks like this: MM-dd-yy hh:mm a

Here’s a table of format characters and what piece of the Date/Time object they display:

Letter Date or Time Piece Examples
G Era G = AD
y Year yy = 09, yyyy = 2009
M Month MM = 08, MMM = Aug, MMMMM = August
w Week in year w = 35
W Week in month W = 3
D Day in year D = 235
d Day in month dd = 27
F Day of week in month F = 2
E Day in week E = Thu, EEEEE = Thursday
a AM/PM a = AM or PM
H Hour in day (0-23) HH = 23
k Hour in day (1-24) kk = 24
K Hour in am/pm (0-11) KK=11
h Hour in am/pm (1-12) hh = 12
m Minutes in hour mm = 30
s Second in minute ss = 55
S Millisecond in second SSS = 888
z Time zone z = EDT, zzzzz = Eastern Daylight Time
Z Time zone offset Z = -0400

So all that leaves to show is an example:

DateTime d = datetime.now();
timeStr = d.format(‘MMMMM dd, yyyy hh:mm:ss a’);

Which results in a value being assigned to timeStr that looks something like this: August 27, 2009 03:15:49 PM

Keep in mind that this doesn’t have to be used for the current time.  You can use this method to format any DateTime object, no matter where you retrieved it from.  For example, you could get the CreatedDate for any object and then use the format command to display it in a Visualforce page.

Good luck..  I hope you find this useful.

Posted in Salesforce Development | Tagged: , | 15 Comments »