Thursday 10 December 2015

System.abortjob() in salesforce

    Batch and Schedule apex jobs aborting using system.abortJob
abortJob(jobId)
Stops the specified job. The stopped job is still visible in the job queue in the Salesforce user interface.
Signature
System.abortJob(String jobId)
Parameters
jobId
Type: String
The jobId is the ID associated with either AsyncApexJob or CronTrigger.

Ø  We need to execute following code in developer console to abort single job.
         EX :   System.abortJob (003j000000QQHjr”);

Ø  We need to execute following code in console to stop multiple jobs.

Id ids = [SELECT id, name FROM ApexClass WHERE Name = 'AccountUpdate'].id;

List<AsyncApexJob> jobs = [SELECT Id, ApexClassId, Status FROM AsyncApexJob WHERE ApexClassId =: ids AND Status IN ('holding','Queued','Preparing')];
System. Debug ('jobsjobsjobsjobsjobs ‘+jobs);
For (AsyncApexJob job: jobs) {
    System.abortJob (job. ID);

}


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

Tuesday 11 August 2015

Generate Xml file in class

Generating XML file in Salesforce…………………………..

Ø  We need start class with global keyword

Ø  XmlStreamWriter Class
The XmlStreamWriter class provides methods for writing XML data.

For more information:


class:

@Restresource(urlmapping = '/accounts/*')
Global class GenerateaccountXML {
   
    webservice static string generatexml(){
        xmlstreamwriter x = new xmlstreamwriter();
        list<account> acc = [SELECT AccountNumber,AccountSource,BillingCity,BillingCountry,DOB__c,Email__c,Name,
            (select name from contacts) FROM Account];
        string xmlstr = '';
        x.writeStartElement(null, 'Accounts', null);
        for(account a : acc){
            if(a.contacts.size()>0){
        x.writeStartElement(null, 'Account', null);
        x.writeCharacters(a.name);
        x.writeEndElement();
        x.writeStartElement(null, 'Accountbillingcity', null);
            if(a.BillingCity == null){
        x.writeCharacters('hyderabad');
            }else{
        x.writecharacters(a.BillingCity);
            }
        x.writeEndElement();
            x.writeStartElement(null, 'contacts', null);
            for(contact c : a.contacts){
                 x.writeStartElement(null, 'contactname', null);
                                     x.writeCharacters(c.name);
                                     x.writeEndElement();            
               
            }
            x.writeEndElement();
            }
        }
        x.writeEndElement();
        xmlstr = x.getXmlString();
        return xmlstr;       
    }
}


Execute following code in console :

string s = GenerateaccountXML.generatexml();
system.debug('account xml file is : ' +s);

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; } }

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!...