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
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 });
}
}
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 });
}
}
No comments :
Post a Comment