• ezdhanhussain
  • NEWBIE
  • 129 Points
  • Member since 2013
  • Salesforce Developer
  • Accenture


  • Chatter
    Feed
  • 3
    Best Answers
  • 4
    Likes Received
  • 1
    Likes Given
  • 12
    Questions
  • 59
    Replies

Hello,

 

Being a business that provides services, I need a third stage of the Salesforce process for when we have won the contract a the end of the Opportunity phase.  This will be for the period where we have won a contract for some business, and it would be great to have Salesforce workflow etc to ensure that we provide what we promised to provide to our customers.

 

It appears to me that Contracts would be the perfect tool, however there is apparently no way of transferring information such as quotations, sales notes, company names or contacts directly from a Salesforce Opportunity into a Salesforce Contract.

 

The people at Salesforce say this ought to be possible with some fairly simple Apex code, but I don't know where to start.  

 

This was clearly an issue back in 2010 - see http://boards.developerforce.com/t5/General-Development/New-to-Sales-force-Convert-Opportunity-to-Contract/td-p/163183 .Annoyingly, the link to the supposed "answer" no longer works.

 

Please help!

 

Best regards,

 

Alex.

Hi I have some 9 sobjects data retrieved via SOQL. Now I want to add all this List's to a Generic List<sobejct> type to perform single DML operation

Can't this be done with out using For-loops ?
I tried addALL method od list
public pagereference sendEmail(){	
engine = new ParsingEngine();
        engine.originalData = mergedTemplate;
        engine.editableAreas = areas;
        engine.replaceForSend();
        
        mergedTemplate = engine.parsedData;
        
       myEmail__c email = new myEmail__c();
       
        
        try {
           
            
            //Since it is a callout, do the sending first. Then do all the DB tasks, which are really only done for tracking purposes.
            CWS.Email emailObject = new CWS.Email();
            emailObject.fromAddress = emailFrom;
           
              
            emailObject.toAddress = recipient.Email;
           
            emailObject.subject = emailSubject;
            emailObject.body = mergedTemplate;
            emailObject.pairs = new List<CWS.Pair>();
            attachlist =[select id,name,body from attachment where id IN : attachlist1];
            //Process the attachments 
           for (attachment att : attachlist) {
                CWS.Pair file = new CWS.Pair();
                
                file.key = att.name;
                file.value = EncodingUtil.base64Encode(att.body);
                emailObject.pairs.add(file);
                att.body = null;
            }
           
            cws.sendEmail(emailObject);
               attachlist.clear();         
            email.id = emailid;
            email.From__c = emailFrom;
            email.To__c =  recipient.Email;
            email.Subject__c = emailSubject;
            email.Body__c = mergedTemplate;
            System.debug('==================111 email.id:'+ email.id);
            System.debug('==================112 email.From__c:'+ email.From__c);
            System.debug('==================113 email.To__c:'+ email.To__c);
            System.debug('==================114 email.Subject__c:'+ email.Subject__c);
            System.debug('==================115 email.Body__c:'+ email.Body__c);
            system.debug('before upsert:::::::');
            upsert email;
            system.debug('After upsert:::::::'+email);
            attachment a = new attachment();
            a.parentid=email.id;
            a.name ='email template';
            a.body = blob.valueof(mergedtemplate);
            upsert a;
            system.debug('attached template in sobjecte::::::::'+a);
            
            
         
           
            //inserting in email sobject to track sent history
            Email__c em = new email__c();
            em.Type__c ='Sent';
            em.Date_Time__c = system.now();
            em.Email__c =recipient.Email;
            if(experienceid.startswith('5')){
            system.debug('Before assgining id case::'+experienceid);
            em.experience__c = experienceid;
            system.debug('after assgining id case::'+em.experience__c);
            }
            else{
             system.debug('Before assgining id promise::'+experienceid);          
            em.promise_date__c = experienceid;
            system.debug('after assgining id promise::'+em.promise_date__c);
            
            }
            em.Assigned_to__c=recipient.ownerid;
            if(action !='' && action!=null){
            em.name =action +'{Ref:'+''+Casenumber+'}' ;
            }
            else {
            em.name ='Follow Up to Your Request'+'{Ref:'+''+Casenumber+'}';
            }
            system.debug('Before attachments');
            insert em;
            list<attachment> newAttachments = new list<attachment>();
            attachment emailAtt = new Attachment();
            emailAtt.ParentId = em.id;
            emailAtt.Name = 'Emailpdf';
            emailAtt.Body = blob.valueof(mergedTemplate);
            emailAtt.contenttype = 'pdf';
            newAttachments.add(emailAtt);
            
            if (newAttachments.size() > 0) {
                try{
                insert newAttachments;
                system.debug('attachments insert in email successfull::::::::::::::');
                }
                catch(exception ex){
                  system.debug('attachments insert in email error::::::::::::::');
                }
                       
            Utils.addMessage(ApexPages.Severity.CONFIRM, Label.Email_Success);
            msg = true;
            emailSent = true;
            getattlist();
        }
}
         catch (Exception e) {
        system.debug('error catch block::::::::::::::');
            Utils.addMessage(ApexPages.Severity.ERROR, Label.Email_error+''+e.getmessage()+e.getLineNumber() );
            msg = true;
            emailsent = true;

        }
}

HI i have a requirement in which i am loading a template from an external server which is in chinese, this template is working fine in external server but when i am trying to display this in visualforce page it is showing like this

如需帮助,请拨打å…�费电è¯�或通过邮件与我们è�”系。身为Visaæ— é™�å�¡æŒ�å�¡äººï¼Œæ‚¨è¿˜å�¯ä»¥å°Šäº«ä»¥ä¸‹ä¼˜è¶Šç¤¼é�‡ï¼š
指定高尔夫俱ä¹�部尊享å…�果岭费优æƒ
ä»¥ä¼˜æƒ ä»·æ ¼åœ¨å…¨ç�ƒ380家机场享å�—机场å��助ã€�快速通关等æœ�务
租车æœ�务折扣优æƒ

When i email the same template it is displaying correctly.. With in the salesforce org it is not formatting prperly. Any suggestions to do this ???
Hi i have a requirement to re-order by pageblocktable rows as needed by using mouse drag functionality ? Can any one suggest possible methods to achieve this ?
I have a requirement ,if amount is less than some predefined amount i am creating a task with reminder. This reminder is poping up and working in a perfect condition untill i am in standard pages, if i navigate to visualforce page this  reminder popup is not opening, if i again get back to standard pages the same popup is working fine...

Any suggestions to achieve this requirement..
Hi, i have a field called Charges__c which would be 0 when record is created.

After 24 hours of record creation charges__c should be updated to a value(assume 200 then 0+200 = 200).

Later after 48 hours charges__c should be updated to(200+200=400).
 
This cycle is repeated every 24 hours. Any Suggestions ? 

Hi i have an sobject in which a picklist with 3 values has been saved. Now i want to give additional values in picklist via a input text box in  visualforce and apex. I am able to fetch the records here. but unable to add values to it.  Adding my code for reference.

<apex:page controller="clientobject">
<apex:form >
 <apex:pageBlock >
  <apex:selectList id="countries" value="{!picklist}" size="1">
  <apex:selectOptions value="{!countries}"/>
</apex:selectList><br/><br/>
  Enter value to add:<apex:inputText value="{!pick}"/>
  <apex:commandButton value="add" />
 </apex:pageBlock>
</apex:form>
</apex:page>
//controller class
public class clientobject {
public string pick{set;get;}
public string picklist{set;get;}
transient List<Schema.PicklistEntry> ple = new List<Schema.PicklistEntry>();
public clientobject(){

}
public List<SelectOption> getCountries(){
  List<SelectOption> options = new List<SelectOption>();
        
   Schema.DescribeFieldResult fieldResult = OfficeLocation__c.Country__c.getDescribe();
  ple = fieldResult.getPicklistValues();
    
        
   for( Schema.PicklistEntry f : ple)
   {
 
      options.add(new SelectOption(f.getLabel(), f.getValue()));
      
   }       
    system.debug('picklist values are ::::::::::'+options);
   return options;
  }
 }

 i don't know how to perform dml actions on schema.describe calls ? Any suggestions would be appreciated

Hi i have a picklist named services__c in client__c sobject. i have 4 values in this. now i want to create a UI where i can add/delete picklist values. Any suggestions would be greatly appreciated ?

Hi i am trying to learn unit testing in salesforce. Below is the code of my controller class. The lines marked as red are not getting covered, can any one suggest me how to do it ? Thanks in advance.

public class RadioButton {
public List<contact> selectcon=new List<contact>();
contact con;
public string selectconid;
Public List<contact> getAllContacts()
{
List<contact> allcons = [Select Id,FirstName,LastName,Email,Phone from Contact LIMIT 10];
return allcons;
}
Public void selectcon()
{
string selectconid = System.currentPagereference().getParameters().get('conid');

con = [Select Id,FirstName,LastName,Email,Phone from Contact where Id=:selectconid limit 1];

selectcon.add(con);

}
Public List<contact> getselectedContact()
{
return selectcon;
}

}

I have a list of  recordswhich are associated with radio buttons individually, when i select radio button of any one record it should redirect me to a new page displaying all the details of that record ? Any ideas will be greatly appreciated..

I Have a sobject name member__c in which there is a field text__c. Text__c has a value called HI. i saved the record.

 

now i changed the value of text__c from HI to new and click on save, after saving it should again display HI in text__c instead of new. 

Is it possible through trigger ? If yes through your valuable suggesstions. This criteria should be met only using after update.

I have a list of leads which i retrieve through query, now i want to convert this list of leads to account and contacts without using any trigger/validation. only through apex code.  Below is code on which i am working.

list<Lead> myLead = [select id,LastName,company from Lead where company='sambodhi'];
return myLead;
for(integer i=0; i<=mylead.size();i++){
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead[i].id);
lc.setAccountid(myLead[i].id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true limit 199
ALL ROWS];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}

HI i have a requirement in which i am loading a template from an external server which is in chinese, this template is working fine in external server but when i am trying to display this in visualforce page it is showing like this

如需帮助,请拨打å…�费电è¯�或通过邮件与我们è�”系。身为Visaæ— é™�å�¡æŒ�å�¡äººï¼Œæ‚¨è¿˜å�¯ä»¥å°Šäº«ä»¥ä¸‹ä¼˜è¶Šç¤¼é�‡ï¼š
指定高尔夫俱ä¹�部尊享å…�果岭费优æƒ
ä»¥ä¼˜æƒ ä»·æ ¼åœ¨å…¨ç�ƒ380家机场享å�—机场å��助ã€�快速通关等æœ�务
租车æœ�务折扣优æƒ

When i email the same template it is displaying correctly.. With in the salesforce org it is not formatting prperly. Any suggestions to do this ???
Hi i have a requirement to re-order by pageblocktable rows as needed by using mouse drag functionality ? Can any one suggest possible methods to achieve this ?
I have a requirement ,if amount is less than some predefined amount i am creating a task with reminder. This reminder is poping up and working in a perfect condition untill i am in standard pages, if i navigate to visualforce page this  reminder popup is not opening, if i again get back to standard pages the same popup is working fine...

Any suggestions to achieve this requirement..
Hi I have some 9 sobjects data retrieved via SOQL. Now I want to add all this List's to a Generic List<sobejct> type to perform single DML operation

Can't this be done with out using For-loops ?
I tried addALL method od list
Hi Everyone,

i have created 2 pages namely page1,page2.
i have created lookup functionality kind in page1,in  which if i click button/lookup icon it will open page2. when i click on button/lookuup icon page2 will get load. when loading page2 ,it is taking time to load completly.
here i want to show process image/loading bar kind. can some one help me how to show process image/loading bar while page is loading.
i hope i'm clear with my question.

Regards
Lakshman
 
I have created a PushTopic as below:
{
    "Name" : "contact_with_notify",
    "Query" : "SELECT Id, LastName, FirstName, Phone from Contact",
    "ApiVersion" : 32.0,
    "NotifyForOperationCreate" : true,
    "NotifyForOperationUpdate" : true,
    "NotifyForOperationUndelete" : true,
    "NotifyForOperationDelete" : true,
    "NotifyForFields" : "SELECT"
}

but no matter what value I set for 'NotifyForFields', subscriptions to this topic only receive notifications when every field in the topic query is changed. How do I modify query so that a notification is sent when ONE field in query changes? Or do I need a topic per field?
Hello Everyone,

We are creating a product that should work very much like the "LiveAgent" . We want to implement a functionality to open multiple primary tabs from a visualforce page created as a custom Service cloud console. In the visualforce page, we have different sections with the "Accept" Button much like the one you see in a LiveAgent during which we are running into an issue with the Service cloud openPrimaryTab API method. I have placed a simple visualforce page in a custom console component and am opening the multiple primary tabs using the below API from service console integration tool kit.

“ sforce.console.openPrimaryTab(null, '/apex/LiveText?id='+recordId, true, 'Chat-'+recordId, openSuccess, 'salesforceTab’); “

The tab opens fine the first time, but from the next time (i.e., when I click on Accept button for the second time) , Since the URL (apex/LiveText) being provided to the openPrimaryTab API is the same (Note: I tried to make the url different by passing the record id, but it does not work), it is rendering the second/ new tab in the existing primary tab.

We have also tried to generate a URL (https://na17.salesforce.com/console#/apex/LiveText?id=a00o0000001DjEzAAK|/001/e|/003/e|/500/e|/00Q/e) with the primary and sub tabs together and tried to open with the Window.open and still the result is same. It just renders the new tabs in the existing open primary tabs.

We have seen this behavior when we open a case record. If a new tab is opened with the case, while there is a tab open with the same case record, instead of opening a new tab, it just renders in the existing tab but not sure if this is the same behavior we should expect with the visualforce pages?

Did anyone run into this issue before and if Yes, how can we resolve it.

*** Opening multiple sub-tabs works fine, but the issue persists with the primary tabs.

Thanks,
Prudhvi Kanteti
how can i pass a javascript variable to apex variable?
i need to use the apex variable on the if condition for list item class style.

PAGE:
<ul>
    <li class="{!IF(a==true && b==false, 'tabStyle1', 'tabStyle2')}">
        P&amp;L Entry
    </li>
    <li class="{!IF(a==false && b==true, 'tabStyle1', 'tabStyle2')}">
        P&amp;L Search
    </li>
</ul>

<div id="DivID1">
    text1
</div>
<div id="DivID2">
    text2
</div>
<style>
    .tabStyle1 {
        backgroound-color: red;
    }
    .tabStyle2 {
        backgroound-color: blue;
    }
</style>


Controller:
public String a {get;set;}
public String b {get;set;}

public void showA() {
     //a = __________;   <----pass this javascript: $("#DivID1").is(":visible");
     //b = __________;   <----pass this javascript: $("#DivID2").is(":visible");
}



  • July 09, 2014
  • Like
  • 0
Hi,

i am having an URL field on account object.
For now i hard coded the value as https://c.na14.content.force.com/servlet/servlet.FileDownload?file=00Pd000000JHoPF
(I am getting image whose name starts with  or contains 'bill' in its name from notes and attachment section and using that.)
I would like to make it dynamic.

My idea is: to create a new text field on account object which holds the attachmentid and create a formula fields which joins URL value and attachment id .
Or else ho can i use it??

I need to use this field /URL in visualforce template.So its required to generate that field in this format:
'https://c.na14.content.force.com/servlet/servlet.FileDownload?file= +attachmentid'

Please help.!!!!!!!



Hi Everyone,
Below is my visualforce page.

<apex:column headerValue="Select" >
     <apex:actionsupport event="onclick" > 
                        <input type="radio" />                   
                            <apex:param name="RepId" value="{!Item.id}">
                        </apex:param></apex:actionsupport>
       </apex:column>
     <apex:column headervalue="Name">
                        <apex:outputfield style="width:2500px" value="{!Item.User__c}">
                    </apex:outputfield></apex:column>
     <apex:column headervalue="Start DateTime">
                        <apex:outputfield value="{!Item.Start_DateTime__c}">
                    </apex:outputfield></apex:column>
      <apex:column headervalue="End DateTime">
                        <apex:outputfield value="{!Item.End_DateTime__c}">
                    </apex:outputfield></apex:column>
      <apex:column headervalue="Approximate Distance To Appointment">
                        <apex:outputfield value="{!Item.Distance__c}">
                    </apex:outputfield></apex:column>
      <apex:column headervalue="Number of events">
                        <apex:outputfield value="{!Item.Number_of_Events__c}">


How can i pass the value of of that row to the controller class.

Thanks in advance.
public pagereference sendEmail(){	
engine = new ParsingEngine();
        engine.originalData = mergedTemplate;
        engine.editableAreas = areas;
        engine.replaceForSend();
        
        mergedTemplate = engine.parsedData;
        
       myEmail__c email = new myEmail__c();
       
        
        try {
           
            
            //Since it is a callout, do the sending first. Then do all the DB tasks, which are really only done for tracking purposes.
            CWS.Email emailObject = new CWS.Email();
            emailObject.fromAddress = emailFrom;
           
              
            emailObject.toAddress = recipient.Email;
           
            emailObject.subject = emailSubject;
            emailObject.body = mergedTemplate;
            emailObject.pairs = new List<CWS.Pair>();
            attachlist =[select id,name,body from attachment where id IN : attachlist1];
            //Process the attachments 
           for (attachment att : attachlist) {
                CWS.Pair file = new CWS.Pair();
                
                file.key = att.name;
                file.value = EncodingUtil.base64Encode(att.body);
                emailObject.pairs.add(file);
                att.body = null;
            }
           
            cws.sendEmail(emailObject);
               attachlist.clear();         
            email.id = emailid;
            email.From__c = emailFrom;
            email.To__c =  recipient.Email;
            email.Subject__c = emailSubject;
            email.Body__c = mergedTemplate;
            System.debug('==================111 email.id:'+ email.id);
            System.debug('==================112 email.From__c:'+ email.From__c);
            System.debug('==================113 email.To__c:'+ email.To__c);
            System.debug('==================114 email.Subject__c:'+ email.Subject__c);
            System.debug('==================115 email.Body__c:'+ email.Body__c);
            system.debug('before upsert:::::::');
            upsert email;
            system.debug('After upsert:::::::'+email);
            attachment a = new attachment();
            a.parentid=email.id;
            a.name ='email template';
            a.body = blob.valueof(mergedtemplate);
            upsert a;
            system.debug('attached template in sobjecte::::::::'+a);
            
            
         
           
            //inserting in email sobject to track sent history
            Email__c em = new email__c();
            em.Type__c ='Sent';
            em.Date_Time__c = system.now();
            em.Email__c =recipient.Email;
            if(experienceid.startswith('5')){
            system.debug('Before assgining id case::'+experienceid);
            em.experience__c = experienceid;
            system.debug('after assgining id case::'+em.experience__c);
            }
            else{
             system.debug('Before assgining id promise::'+experienceid);          
            em.promise_date__c = experienceid;
            system.debug('after assgining id promise::'+em.promise_date__c);
            
            }
            em.Assigned_to__c=recipient.ownerid;
            if(action !='' && action!=null){
            em.name =action +'{Ref:'+''+Casenumber+'}' ;
            }
            else {
            em.name ='Follow Up to Your Request'+'{Ref:'+''+Casenumber+'}';
            }
            system.debug('Before attachments');
            insert em;
            list<attachment> newAttachments = new list<attachment>();
            attachment emailAtt = new Attachment();
            emailAtt.ParentId = em.id;
            emailAtt.Name = 'Emailpdf';
            emailAtt.Body = blob.valueof(mergedTemplate);
            emailAtt.contenttype = 'pdf';
            newAttachments.add(emailAtt);
            
            if (newAttachments.size() > 0) {
                try{
                insert newAttachments;
                system.debug('attachments insert in email successfull::::::::::::::');
                }
                catch(exception ex){
                  system.debug('attachments insert in email error::::::::::::::');
                }
                       
            Utils.addMessage(ApexPages.Severity.CONFIRM, Label.Email_Success);
            msg = true;
            emailSent = true;
            getattlist();
        }
}
         catch (Exception e) {
        system.debug('error catch block::::::::::::::');
            Utils.addMessage(ApexPages.Severity.ERROR, Label.Email_error+''+e.getmessage()+e.getLineNumber() );
            msg = true;
            emailsent = true;

        }
}

Hello Everyone,

I have observed a wired behavior with "Blob.toPDF(<string>)" Salesforce Apex API's , this method strips off Chinese characters and there is no option to set character encoding, please find below the sample code.


String targetString = 'Before - 測試中文字 - After';

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(targetString); //This creates the PDF content
insert attachmentPDF;

I have also tried encoding Chinese character content to UTF-8 but this displays all the encoded characters in PDF,

String targetString = 'Before - 測試中文字 - After';
String encodedString = EncodingUtil.urlEncode(targetString,'UTF-8');
System.debug('##encodedString:-'+encodedString);

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(encodedString); //This creates the PDF content
insert attachmentPDF;

Please help.

Thanks
-Tejas(+91 9663266726)
Hi All,

I am currently working on a Apex class, That's perform different functionalities.

Like pagination, search by keyword, and selecting the records and sending some of the data to second page. And in second page have some input text fields that were not a object fileds inturn they are individual fields which will autopopulate with default values when redirected from first page. Now here i need to enter the data for some input fields and on button click it will calculate the rest of the inpit fileds based on the data provided. Fot this calculation and passing the data i am writing a javascript junction. Here i am coming up with  a problem.

The problem is-
the values that were calculated in page using javascript were not passing to controller. Please can anyone help me on how to acomplish this task..
Here i have a pageblock table records that needs to be passed to controller.

Thank You.

Hi, The below code through a error" 'NotesAndAttachment' is not a valid child relationship name for entity Account" and i have one custom object but i don't no how it display.And the below code execute in 28.0 version,but not execute in 29.0 ,why?

 

<apex:page standardController="Account" showHeader="false"
tabStyle="account" >
<apex:stylesheet id="customstylesheet" value="customstylesheet"/>
<style>
.activeTab {background-color: yellow; color:red; font-format:italic;font-size:19pt;
background-image:none}
.inactiveTab { background-color: lightgrey; color:black;
background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab="tabdetails"
id="AccountTabPanel" tabClass="activeTab" >
<apex:tab label="Details" name="AccDetails" id="tabdetails" >
<apex:detail relatedList="true" title="true" />
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact" style="customstylesheet">
<apex:relatedList subject="{!account}" list="contacts" />
</apex:tab>
<apex:tab label="Opportunities" name="Opportunities"
id="tabOpp">
<apex:relatedList subject="{!account}"
list="opportunities" />
</apex:tab>
<apex:tab label="Open Activities" name="OpenActivities" styleClass="newlink"
id="tabOpenAct">
<apex:relatedList subject="{!account}"
list="OpenActivities" />
</apex:tab>
<apex:tab label="Notes and Attachments"
name="NotesAndAttachments" id="tabNoteAtt">
<apex:relatedList subject="{!account}"
list="NotesAndAttachment" />
<apex:tab label="customobject" name="customobject">
<apex:relatedList list="customobject__r"/>
</apex:tab>
</apex:tab>
</apex:tabPanel>
</apex:page>

 

thanks

Ramesh

  • November 11, 2013
  • Like
  • 0
Hello Everyone,

I have observed a wired behavior with "Blob.toPDF(<string>)" Salesforce Apex API's , this method strips off Chinese characters and there is no option to set character encoding, please find below the sample code.


String targetString = 'Before - 測試中文字 - After';

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(targetString); //This creates the PDF content
insert attachmentPDF;

I have also tried encoding Chinese character content to UTF-8 but this displays all the encoded characters in PDF,

String targetString = 'Before - 測試中文字 - After';
String encodedString = EncodingUtil.urlEncode(targetString,'UTF-8');
System.debug('##encodedString:-'+encodedString);

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(encodedString); //This creates the PDF content
insert attachmentPDF;

Please help.

Thanks
-Tejas(+91 9663266726)