Sunday, 8 February 2015

Trigger on task object by using messaging class

Require ment:
 
/* whenever task is completed we need send
confirmation mail to related account....

*/

Trigger Send_Email on Task (after insert,after update) {

list<account> acc;

for(Task tsk : Trigger.New)
{

if(tsk.status == 'completed'){

acc = [select name,email__C from account where id =: tsk.whatid];
}
}
for(account a :acc){
if(a.email__c != null){

string mal = a.email__C;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {mal};
mail.setToAddresses(toAddresses);  
mail.setSubject('A task owned by you has been updated');  
String body = 'Dear ' + a.name + ', ';
        body += 'I am informing about your task .';
        body += 'I am varaprasad CEO of salesforce.';
        body += 'your task is completed succesfully.. ';
       
mail.setHtmlBody(body);

Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});


}
}
}

                             

Tuesday, 3 February 2015

Global Variables In salesforce

Use global variables to reference general information about the current user and your organization on a page.

More Info about Global variables follow below link.

http://www.salesforce.com/docs/developer/pages/Content/pages_variables_global.htm




                       Global Variable info on visual force page

 

<apex:page standardController="Account" extensions="DemoController" sidebar="false"> 
<apex:form >  

   <apex:pageblock >  
       <center>

            <b> Userid :  <apex:outputText value="{!LoggedInUSerId}"/> <br></br> </b>

           <b> User Name : <apex:outputText value="{!uname}"/> <br></br> </b>

           <b> profilename : <apex:outputText value="{!$Profile.Name}"></apex:outputText></b>

           <b> User Name : <apex:outputText value="{!$User.LastName}"/> <br></br> </b> 

           <b> User Role: <apex:outputText value="{!$UserRole.Name}"/> <br></br> </b>

            <b> Static Recourse : <apex:outputText value="{!$Resource.bulbon}"/> <br></br> </b>

           </center>        

    </apex:pageblock>

  </apex:form>

</apex:page>

 ----------------------------------------------------------------------------------------------------------------

public class DemoController {

    public id LoggedInUSerId{get;set;}
     public string uname{get;set;}
    public string pname{get;set;}

  public DemoController(ApexPages.StandardController controller) {
     LoggedInUSerId = userinfo.getuserid();
     uname = userinfo.getusername();

    }
}
 

Thursday, 15 January 2015

Email services 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.

Basic Synatx:



Before creating email services, create Apex classes that implement the Messaging.InboundEmailHandler interface.

  global class myHandler implements Messaging.InboundEmailHandler {
     global Messaging.InboundEmailResult handleInboundEmail(
 Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
 Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
          return result;
      }
  }

Examples:

example 1:

global class createcontact implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { Messaging.InboundEmailResult result = new Messaging.InboundEmailresult(); Contact contact = new Contact(); contact.FirstName = email.fromname.substring(0,email.fromname.indexOf(' ')); contact.LastName = email.subject; contact.Email = envelope.fromAddress; contact.LeadSource = 'other'; insert contact; System.debug('====> Created contact '+contact.Id); return result; } }
----------------------------------------------------------------
example 2:
global class createevent1 implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { Messaging.InboundEmailResult result = new Messaging.InboundEmailresult(); event e = new event(); e.Ownerid='00590000002dteE'; e.Subject = 'email'; e.StartDateTime = system.Now(); e.EndDateTime = system.Now()+1; insert e; System.debug('====> Created event '+e.Id); return result; } }

Wednesday, 3 December 2014

REST WEB SERVICES

                  REST WEB SERVICES



REST:
            Stands for: Representational state  transfer
Rest is :
Ø Stateless
Ø Client – server based
Ø HTTP Based
Ø It is not a protocol
Ø Support Both JSON and XML

@RestResource:
In Rest web services we need to implement @Rest Resource annotation .
We need to map endpoint URL  here   .
Syntax: @RestResource(urlMapping =’/endpoint url/*’..
Then we need to implement class with following Http methods
@Httppost  = create
@Httpget = read
@Httpput = update
@Httpatch = update
@Httpdelete = delete

Then we need implement following
Restcontext : it is a container class it holds  twoobjects
Restrequest:  params,requestbody,requestpath
Restresponse: return messages etc

@RestResource(urlMapping = '/v29/account/*')
    global class restwebservices{
   
    @Httpget
    global static account getdetails(){
        Restrequest req = restcontext.request;
        Restresponse res = restcontext.response;
        string name = req.requestURI.substring(req.requestURI.lastindexof('/')+1);
        account a = [select id,name,phone,type,website,rating from account where name =: name];
        return a;
   
    }
    @Httppost
    global static id createaccont(string name,string phone,string website){
        Restrequest req = restcontext.request;
        Restresponse res = restcontext.response;
        account a = new account();
        a.name = name;
        a.phone = phone;
        a.website = website;
        insert a;
        return a.id;
        }
  }
    


                                                                                 




Sunday, 23 November 2014

How to convert integer to string in apex

Example of conversion of integer to string

      integer i=123;

      string s1=string.valueof(i);



Example of conversion of string to integer

    string s='123';

    integer i=integer.valueof(s);

capitalize()
Returns the current String with the first letter changed to title case.

String s = 'varaprasad';
String s2 = s.capitalize();
System.debug('convert first letter to capitalize' +s2);

center(Integer)
Returns a version of the current String of the specified size padded with spaces on the left and right, so that it appears in the center. If the specified size is smaller than the current String size, the entire String is returned without added spaces.

String s1 = 'hello';
String s3 = s1.center(9);
System.debug('.put center..' +s3);




Visualforce Actionsupport examples



<apex:page controller="actionSupport6">
  <apex:form >
      <apex:outputPanel id="test">
          <apex:pageBlock >
              Enter Text1:<apex:inputText value="{!text1}"/>
                            <br/><br/><br/><br/>
            
              Enter Text2:<apex:inputText value="{!text2}">
                                <apex:actionSupport event="onmouseover" action="{!CallMethod}" reRender="test"/>
                          </apex:inputText>
          </apex:pageBlock>
      </apex:outputPanel>
  </apex:form>
</apex:page>


public class actionSupport6
{

    public String text1{get;set;}
    public String text2{get;set;}
    
    public void CallMethod()
    {
       
        text2 = text1;
    } 
}


===============================================================





<apex:page standardController="Contact" extensions="ActionSupport">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection id="appraiserInfo">
                <apex:inputField value="{!Contact.firstname}"/>

               </apex:pageBlockSection>
                 <apex:inputField label="Company" value="{!contact.AccountId}">
                      <apex:actionSupport action="{!UpdateContactDetails}"  event="onchange" rerender="appraiserInfo" />
                  </apex:inputField>
        </apex:pageBlock>
    </apex:form>
 
</apex:page>

===========================================================

public class ActionSupport {

    public contact conObj;
    public ActionSupport(ApexPages.StandardController controller)
    {
        conObj=(Contact)controller.getRecord();
    }
    public void UpdateContactDetails()
    {
        system.debug('Method is Calling with id===>'+conObj.Accountid);
       
        Account Varacc=[select id,name from Account where id=:conObj.Accountid];
        conObj.firstname=Varacc.name;
    }

}


Wednesday, 12 November 2014

Difference between “apex:dataTable” and “apex:pageBlockTable”


Both component is used to render data in tabular format. dataTable will render records in simple HTML table format whereas the “pageBlockTable” possess default look and feel of salesforce standard CSS and must be written inside “apex:pageBlock” componet.
You can read more here.

PageBlockTable:
PageBlockTable should be defined inside pageblock or pageblocksection.
PageBlockTable uses standard styles sheets to design a visualpage.
It has the  required attribute "value".
Column headers  will be displayed automatically.

DataTable:
No need to write inside pageblock or pageblocksection.
There is no required value.
The  data can be displayed using  custom style sheets.
 we need to specify column headers explicitly.




Complete Salesforce CPQ training Free videos

Salesforcestart:: We are excited to announce that our YouTube channel, Salesforcestart, is your one-stop-shop for all things Salesforce CPQ!...