Friday, April 4, 2014

Create Calender from salesforce to Google,Yahoo, Outlook

Adding an event from salesforce

Visualforce page:

<apex:page controller="CalenderConnect">
<apex:form >
  <apex:commandLink value="Add Event to My Calender" action="{!displayCalender}"/><br/>
  <apex:outputPanel rendered="{!calenderShow}">
  <apex:pageMessages ></apex:pageMessages>
  <apex:outputLabel value="Outlook Email:"></apex:outputLabel>
  <apex:inputText value="{!emailValue}"/>
  <apex:commandLink action="{!outlookConnect}" value="OutLook"/><br/>
  <apex:commandLink target="_blank" action="{!doYahooconnectCall}" value="Yahoo"/><br/>
  <apex:commandLink target="_blank" action="{!googleConnectCall}" value="Google"/>
  </apex:outputPanel>
</apex:form>
</apex:page>

Apex Controller

public class CalenderConnect {
    public Boolean calenderShow { get; set; }
    public String emailValue { get; set; }

    public PageReference displayCalender() {
        calenderShow =true;
        return null;
    }
    public PageReference outlookConnect() {
        System.debug(emailValue);
        if(emailValue ==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Email Address Should be specified')); }
        try{
        String vCal = 'BEGIN:VCALENDAR'+ '\n'
                            +'VERSION:1.0' + '\n'
                            +'BEGIN:VEVENT' + '\n'
                            +'URL:Site Url'+ '\n'
                            +'DTSTART:20140329T223000Z'+ '\n'
                            +'DTEND:20140330T023000Z'+ '\n'
                            +'SUMMARY:Message'+ '\n'
                            +'DESCRIPTION:Body Message'+ '\n'
                         +'LOCATION:Class of 1923 Ice Rink - 3130 Walnut St - Philadelphia, PA 19104'+'\n'
                            +'END:VEVENT'+ '\n'
                            +'END:VCALENDAR'+ '\n';
        List<String>toAddresses = new List<String>();
        toAddresses.add(emailValue);
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setSubject('Test');
        email.setToAddresses(toAddresses);
        email.setHtmlBody('Test');
        email.setPlainTextBody('Test');
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName('invite.ics');
        efa.setBody(Blob.ValueOf(vCal));
 
        //attachments.add(efa);
        efa.setContentType('text/calendar');
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
         Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        }
        catch(Exception e){
            System.debug(e.getMessage()+e.getStackTraceString());
        }
        return null;
    }
    public PageReference googleConnectCall() {
        PageReference pr = new PageReference('https://www.google.com/calendar/render?action=TEMPLATE'+
                            '&text=Scheduling the Meeting at Test Message'+
                            '&dates=20140329T223000Z/20140330T023000Z'+
                            '&details=Body of the event'+
                            '&location=Location Where the meeting is going to hel    d'+
                            '&output=xml');
            System.debug(pr);
        return pr;
    }
    public Pagereference doYahooconnectCall(){
        PageReference pr = new PageReference('https://calendar.yahoo.com/?v=60&view=d'+
                               '&type=20'+
                               '&title=Scheduling the Meeting at Test Message'+
                               '&st=20140329T223000Z&dur=0400'+
                               '&desc=Body of the event' +
                               '&in_loc=Location Where the meeting is going to held');
            System.debug(pr);
        return pr;
    }
}
 
   
 

Bar Code and QR code From Vf page to Email

Create a formula field in Contact object with any of the code(QR,Bar Code).  Before clicking on the email button in the vf page pass the id as the parameter in the url.

The formula would be
QR Code
IMAGE('https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=MECARD:N:' + FirstName + ' ' + LastName +';ADR:'+ MailingStreet +',' + MailingCity + ',' + MailingState + ',' + MailingCountry + ',' + MailingPostalCode + ';TEL:'+ MobilePhone +';EMAIL:' + Email + ';', 'Scan the QR code' )

Bar Code
IMAGE("http://www.barcodesinc.com/generator/image.php?code="+Id+"&style=325&type=C128B&width=200&height=50&xres=1&font=3" ,"Barcode")

Vf Page Code
<apex:page standardController="Contact" extensions="BarcodeController">
<apex:form >
<!-- <apex:inputField value="{!contact.QR_Code__c}"/>
<apex:inputField value="{!contact.Bar_Code__c}"/> -->

<apex:commandButton value="sendEmail" action="{!sendEmail}"/>
</apex:form>
</apex:page>

Apex Controller
public class BarcodeController {
    public Contact cont;
    public Id contactId; 

    public BarcodeController(ApexPages.StandardController controller) {

        //cont=(Contact)controller.getRecord();
        contactId=controller.getId();
    }
    
    public void sendEmail(){
        if(contactId !=null || contactId != ''){
            Cont=[select Id,Bar_Code__c,Qr_Code__c from Contact where id = : contactId limit 1];
        }
        String email='xxx@gmail.com';
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setToAddresses(new String[] { email });
            mail.setSubject('Bar Code and the Q.R Code Demo');
           
            String body = cont.Bar_Code__c+
                        +cont.Qr_Code__c;
            mail.setHtmlBody('Scan the Qr code and the Bar code'+body );
     
        // Send the email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }

}


Thursday, April 3, 2014

Get record id from standard controller using Apex in Salesforce?



Sample Code:

Visualforce page:
<apex:page standardcontroller="account" extensions="SampleController">
{!accountid}
</apex:page>

Apex Controller:

public class SampleController {

    public Id accountid {get;set;}
  
    public Sample(ApexPages.StandardController controller) {
        Account acc = new Account();
        accountid = controller.getId();
    }       
}

Labels

visualforce page ( 13 ) apex integration ( 5 ) apex trigger ( 4 ) csv file from vf page ( 4 ) javascript ( 4 ) csv visualforce page ( 3 ) Too many ( 2 ) call out ( 2 ) integration ( 2 ) rest api ( 2 ) salesforce rest api ( 2 ) salesforce to salesforce integration ( 2 ) sfdc rest api ( 2 ) trigger ( 2 ) 15 digit to 18 digit ( 1 ) DML rows in Apex ( 1 ) Date Conversion ( 1 ) Date/Time conversion ( 1 ) Deploy ( 1 ) Objects to Future Annotated Methods ( 1 ) SFDC limits ( 1 ) Sobject to Future Annotated Methods ( 1 ) Test Class ( 1 ) TimeZone Conversion ( 1 ) Too many dml rows ( 1 ) Too many future calls ( 1 ) annotations ( 1 ) apex code ( 1 ) closed opportunities ( 1 ) commit ( 1 ) convert ( 1 ) create records ( 1 ) csv create records ( 1 ) custom setting ( 1 ) deployment ( 1 ) deployment changeset ( 1 ) disable apex class ( 1 ) disable apex trigger ( 1 ) disable in production ( 1 ) document ( 1 ) download ( 1 ) field name ( 1 ) formula fields ( 1 ) iframe ( 1 ) inactive ( 1 ) intellisense ( 1 ) jsforce ( 1 ) limits ( 1 ) matrix report in vf page ( 1 ) multi select ( 1 ) multi select salesforce ( 1 ) multiselect ( 1 ) paypal ( 1 ) picklist ( 1 ) record type ( 1 ) rollback ( 1 ) salesforce limits ( 1 ) salesforce list ( 1 ) salesforce map ( 1 ) salesforce rest ( 1 ) salesforce set ( 1 ) salesforce1 ( 1 ) sandbox deployment ( 1 ) sfdc collection ( 1 ) sfdc list ( 1 ) sfdc map ( 1 ) sfdc rest ( 1 ) sfdc set ( 1 ) uncommitted ( 1 ) updated field ( 1 ) user ( 1 ) validation rule opportunity ( 1 ) validation rules opportunities ( 1 ) vf page ( 1 )

Ad