Friday, August 12, 2011

Sending Email With Salesforce Content as Attachment

Hey Guys,

Finally i did it.I had to send multiple salesforce contents as attachments with the Email.
I was stucked for 3 days and finally its Done.

tada here is the help.....

  ///tempList is a list that contains that contains the ContentDocumentIds of the selected Contents

  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  Contact contact = [select Email from Contact where ID=:test.ContactTo__c];
  toaddress.add(contact.email);

  mail.setToAddresses(toaddress);
  mail.setSubject(subject);
  mail.setPlainTextBody(body.replace('&','&'));
  mail.setUseSignature(false);

  Messaging.EmailFileAttachment[] attach = new Messaging.EmailFileAttachment[tempList.size()];
 
  ContentVersion[] contentVersion = new ContentVersion[tempList.size()];
               
  for(integer i=0;i<tempList.size();i++)
        {
          Blob attachBody;
 
          Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
          String temp1 = tempList[i];
 
          contentVersion[i] = [Select id,Title,VersionData,PathOnClient from
                                ContentVersion WHERE ContentDocumentId =: temp1];

          attachBody = contentVersion[i].VersionData;
 
          String str = contentVersion[i].PathOnClient
                                        .substring(contentVersion[i].PathOnClient.indexOf('.')+1
                                        ,contentVersion[i].PathOnClient.length());

          efa.fileName = contentVersion[i].Title+'.'+str;
          efa.setInline(false);
          efa.Body=attachBody;
          attach[i]=efa;
        }
       
        
  if(tempList.size()>0)
          mail.setFileAttachments(attach);

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


Hope it helps.

Enjoy Salesforcing......

Get a list of all SalesForce objects in an Organization

Hello all,
I had spend a lots of time in getting a list of SalesForce Objects including the custom ones.
I know its fairly simple but may be it can provide help to noobs like me.





Friday, July 15, 2011

Send Web Request & XML Parsing

Hello all ,

Here is a complete procedure to send an HTTP web request and parse an XML response returned from the server.

To Do this you must relate your webserver address under remote settings. To do this follow the following steps:

1) Goto Setup under your Name

2) On left pane you can see Administration Setup. Click on Remote Site Settings


3) Click on New Remote Site and register the url


Now you can make requests.

Send Request: In this method i have also used a Method to do encoding

EncodingUtil.urlEncode('varible whose value you wish to encode','Encoding Method').
sig is just a variable that i wish to encode and append in the url.



Parsing: We are using DOM Parser here.It analyses the root elements, walks through each child element and fetches the values.








Enjoy hope it helps in Salesforce
:)

Publish record to Workspaces (Libraries)

Hello all,

I had a hard time searching about how to publish record to workspaces(now Libraries).
but finally i achieved it.Thanks to those who helped me & trusted too.

Here you go:

Publish to SHARED WORKSPACE:


Workspace Name is the choice given by user where he wants to publish the contents
There is also an option if you specify FirstPublishLocationId as id of the shared workspace to which you wish to publish, then you need not to specifically add it to workspace.Just add this line: 

and remove the docLink feature that you can see in the first image.


Publish to PERSONAL WORKSPACE:


doc.FirstPublishLocationID :  We provide user id here indicating that we want to publish the content to the particular user's library.This is necessary to do as there is no API to fetch users personal library Contents.

I have created blobs for testing .You can create blobs depending upon your requirement.
Enjoy Salesforcing.

Monday, July 4, 2011

Update Chatter in VisualForce Page

Hello Chatter feature in Salesforce acts like notification.
You can see the latest activity of the users.

Suppose after uploading a file to server you want to display a notification in chatter then proceed like this:

1) Click on "Start Upload" Button:

2) This is actually apex command button.
3) call a method on its action



4) The action attribute fires a method of a controller class:


5) After uploading or when certain task is finished depending upon users requirement a message is displayed in Chatter like this:


  
Enjoy Salesforcing
:)

Thursday, June 30, 2011

Calling Controller method From JavaScript in Salesforce

Hello,

There are often issues in calling controller class methods from javascript.
Here is a 3 step process.

1) Create a method in Controller class that returns PageReference





2) Create a method in Javascript from where you have to call the controller class method.

For this you have to create a Apex function (say uploadFiles).This acts as a bridge between the two methods




3) Now call this apex function from javascript method which will call your controller class method





Its Done...

Pass Values between SalesForce Pages


Hello,

Many a times we are in a situation when we want to pass values between the Apex pages.
Here is a 4 step process to do it.

Step 1 : Create a link label on the click of which you redirect the user to different page and pass values to it.



Step 2 : When u click on the link label and you are redirected to another page u can see the url which has the parameter appended to it



Step 3 : How to fetch value from the url


Step 4 : How to display the received value on the page



Enjoy SalesForcing....
:)