Friday, May 6, 2011

Inbound email service for Salesforce.com

Email Service is way by which we can create/write inbound message in salesforce.

Email services are automated processes that use Apex classes to process the contents, headers, and attachments of inbound email. For example, you can create an email service that automatically creates contact records based on contact information in messages.

We can associate each email service with one or more Salesforce-generated email addresses to which users can send messages for processing. To give multiple users access to a single email service, you can:
■Associate multiple Salesforce-generated email addresses with the email service and allocate those addresses to users.
■Associate a single Salesforce-generated email address with the email service, and write an Apex class that executes according to the user accessing the email service. For example, you can write an Apex class that identifies the user based on the user's email address and creates records on behalf of that user.
To use email services, click Your Name | Setup | Develop | Email Services.
■Click New Email Service to define a new email service.
■Select an existing email service to view its configuration, activate or deactivate it, and view or specify addresses for that email service.
■Click Edit to make changes to an existing email service.
■Click Delete to delete an email service.
Note
Before deleting email services, you must delete all associated email service addresses. When defining email services, note the following:
■An email service only processes messages it receives at one of its addresses.
■Salesforce limits the total number of messages that all email services combined, including On-Demand Email-to-Case, can process daily. Messages that exceed this limit are bounced, discarded, or queued for processing the next day, depending on how you configure the failure response settings for each email service. Salesforce calculates the limit by multiplying the number of user licenses by 1,000. For example, if you have ten licenses, your organization can process up to 10,000 email messages a day.
■Email service addresses that you create in your sandbox cannot be copied to your production organization.
■For each email service, you can tell Salesforce to send error email messages to a specified address instead of the sender's email address.
■Email services rejects email messages and notifies the sender if the email (combined body text, body HTML and attachments) exceeds approximately 10 MB (varies depending on language and character set).

More link
http://blog.jeffdouglas.com/2010/03/12/writing-an-inbound-email-service-for-salesforce-com/

Thursday, May 5, 2011

Calling Web Services from a Trigger in Salesforce

Please go through the below example for that
we have and object Rndcenter which have two filed tempratureinC,tempratureinF.
When we entered any new record in to this object, user entered firstvalue(tempratureinC) and whith the help of trigger and webservice we got the second value(tempratureinF) and undate the recodes over the object.

Now i am going to drill down the concepts in steps:-
Step 1: Create a object RndCenter
Step 2: Consume WebService
web service information

http://www.w3schools.com/webservices/tempconvert.asmx
http://www.w3schools.com/webservices/tempconvert.asmx?WSDL
and create a class over the sfdc

Step 3: Create Trigger

trigger rnd1 on RndCenter__c (after insert)
{
RndCenter__c rnc=trigger.new[0];
TempConvertWebService.callTempConvertWebService(rnc.id);
}
step 4 :Create a class which call webservice

public class TempConvertWebService
{
@future (callout=true)
public static void callTempConvertWebService(string inputval1)
{
try
{
RndCenter__c rnc=new RndCenter__c();
rnc=[select tempratureinC__C,tempratureinF__c from RndCenter__c where id=: inputval1];
tempuriOrg.TempConvertSoap objtem=new tempuriOrg.TempConvertSoap();
string outtem= objtem.FahrenheitToCelsius(rnc.tempratureinC__C);
rnc.tempratureinF__c=outtem;
update rnc;
}
catch(System.AsyncException e)
{ System.debug( '****Exception' +e ) ;}
}
}

Some time we faced some exception
System.AsyncException: Future method cannot be called from a future method.
Above exception comes due to recursive call of the method(Future),we can resolve this by using a static variable in the class .

Monday, April 11, 2011

Tuesday, April 5, 2011

Salesforce: controller methods(Action,Getter,Setter)

Visualforce markup can use the following types of controller extension and custom controller methods:

1)Action
2)Getter
3)Setter

Action Methods

Action methods perform logic or navigation when a page event occurs, such as when a user clicks a button, or hovers over an area of the page. Action methods can be called from page markup by using {! } notation in the action parameter of one of the following apex tags:
1)commandButton - creates a button that calls an action
2)commandLink - creates a link that calls an action
3)actionPoller- periodically calls an action
4)actionSupport- makes an event (such as “onclick”, “onmouseover”, and so on) on another, named component, call an action
5)actionFunction- defines a new JavaScript function that calls an action
6)page - calls an action when the page is loaded
For example, in the sample page in Building a Custom Controller, the controller's save method is called by the action parameter of the tag. Other examples of action methods are discussed in Defining Action Methods.

Getter Methods
Getter methods return values from a controller. Every value that is calculated by a controller and displayed in a page must have a corresponding getter method, including any Boolean variables. For example, in the sample page in Building a Custom Controller, the controller includes a getAccount method. This method allows the page markup to reference the account member variable in the controller class with {! } notation. The value parameter of the tag uses this notation to access the account, and dot notation to display the account's name. Getter methods must always be named getVariable.

Setter Methods
Setter methods pass user-specified values from page markup to a controller. Any setter methods in a controller are automatically executed before any action methods.

Setter methods must always be named setVariable.

More Information

Salesforce Order of Execution

Hello All,
Today we are going to understad the Salesforce order of Execution,ie when we done some DML oprstion as insertupdate, or upsert statement, Salesforce performs the following events in order
The browser runs JavaScript validation if the record contains any dependent picklist fields and then Salesforce executes these events on the server. The validation limits each dependent picklist field to its available values. No other validation occurs on the client side.
Here is order of execution in salesforce
  • The original record is loaded from the database.
  • System Validation Rules.
  • Executes all before triggers.
  • Custom Validation rules.
  • Executes duplicate rules.
  • Saves the record to the database, but doesn’t commit yet.
  • Executes all after triggers.
  • Executes assignment rules.
  • Executes auto-response rules.
  • Executes workflow rules.
  • If there are workflow field updates, updates the record again.
  • If the record was updated with workflow field updates, fires before and after triggers one more time. Custom validation rules, duplicate rules, and escalation rules are not run again.
  • Executes processes and flows launched via processes and flow trigger workflow actions.
  • Executes escalation rules.
  • Executes entitlement rules.
  • If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
  • If the parent record is updated, and a grandparent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the grandparent record. Grandparent record goes through save procedure.
  • Executes Criteria Based Sharing evaluation.
  • Commits all DML operations to the database.
  • Executes post-commit logic, such as sending email.

We have diffrent order of Exisuxtion as well as ,we can see these details over the below links