• Sotos
  • NEWBIE
  • 35 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
I am new to the Apex and am see if someone can help me understand how I go about testing a method that gets its data from a List that is an sObject when the parameter that I pass in is the String of the query. I am having trouble figuring out how to get the execute method to test successfully.

The following is my Apex Batchable Class:
 
global class MyBatchJob implements Database.Batchable<sObject>{

    global string query;

       
    global MyBatchJob(){
        String query = 'SELECT      account.id, ' +
                                   'account.name, ' +
                                   'account.industry, ' +
                                   'account.ownerId, ' +
                                   'account.owner.firstname,' +
                                   'account.owner.lastname,'+
                                   'account.recordtypeid, '+
                                   'account.recordtype.name,' +
                                   'account.type, ' +
                                   'Level_of_Effort__c,' +
                                   'Name, ' +
                                   'Ownerid, ' +
                                   'Owner.firstname, ' + 
                                   'Owner.lastname, ' +
                                   'Solution_Complexity__c, ' +
                                   'StageName, '+
                                   'Annualized_Revenue__c,' +
                                   'Amount, ' +
                                   'FTEs__c, ' +
                                   'TotalNumberofSeats__c ' +                              
                                   'FROM Opportunity';     
    } 

    global Database.QueryLocator start(Database.BatchableContext BC){
        System.debug('Started the Batch job to copy key Opportunity Record fields.');
        System.debug('The current Batch unique identifier for this job is : '+ BC.getJobId());
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC,List<Opportunity> scope) {
        System.debug('Executed the Batch job to copy Opportunity Records.');
        System.debug('The current Batch unique identifier for this job is : '+ BC.getJobId());
        List<Opportunity_Snapshot__c> snapList = new List<Opportunity_Snapshot__c>();

                 //Assuming the snapshots you want are of Contact data
		        for(Opportunity opp: scope) {
                 //create a sObject NOT an sObject List to hold the data until I add to the List with snapList.add(snap)
                 //This is a lot like creating a JSON framework in Javascript
                    Opportunity_Snapshot__c snap = new Opportunity_Snapshot__c();
            
                    //start adding to the snap variable from the query results
                    snap.Ss_Account_Id__c                       = opp.AccountId;
                    snap.Ss_Account_Industry__c                 = opp.Account.Industry;
                    snap.Ss_Account_Name__c                     = opp.Account.Name;
                    snap.Ss_Account_Owner_Id__c                 = opp.Account.OwnerId;
                    snap.Ss_Account_Owner_Name__c               = opp.Account.Owner.Firstname + ' ' + opp.Owner.Lastname;
                    snap.Ss_Account_Recordtype_Id__c            = opp.account.recordtypeid;
                    snap.Ss_Account_Recordtype_Name__c          = opp.account.recordtype.name;
                    snap.Ss_Account_Type__c                     = opp.Account.Type;
                    snap.Ss_Opportunity_Amount__c               = opp.Amount;
                    snap.Ss_Opportunity_Annualized_Revenue__c   = opp.Annualized_Revenue__c;
                    snap.Ss_Opportunity_Level_of_Effort__c      = opp.Level_of_Effort__c;
                    snap.Ss_Opportunity_Name__c                 = opp.Name;
                    snap.Ss_Opportunity_Owner_Id__c             = opp.Ownerid;
                    snap.Ss_Opportunity_Owner_Name__c           = opp.Owner.firstname + ' ' + opp.Owner.lastname;
                    snap.Ss_Opportunity_Solution_Complexity__c  = opp.Solution_Complexity__c;
                    snap.Ss_Opportunity_Stage_Name__c           = opp.StageName;
                    snap.Ss_Opportunity_Total_FTE__c            = opp.FTEs__c;
                    snap.Ss_Opportunity_Total_Seats__c          = opp.TotalNumberofSeats__c;

                    //Let's now add these variables to the list to be inserted at the end of the loop.
                    snapList.add(snap); 
  
          
        } 
        insert snapList; 
   }

   global void finish(Database.BatchableContext BC) {
        System.debug(LoggingLevel.WARN,'Batch Job is Complete!!!!!');
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[]{'any@gmail.com', 'any@outlook.com'};
        mail.setToAddresses(toAddresses);
        mail.setSubject('Email Batch Worked');
        mail.setPlainTextBody ('Batch Job worked');
    }
}
So far I have 29% successfully tested.
 
@isTest
public class TestMyBatchJob {
    public static testmethod void TestBatchJob(){
        Test.startTest();
        MyBatchJob bj = new MyBatchJob();
        bj.query=      'SELECT      account.id, ' +
                                   'account.name, ' +
                                   'account.industry, ' +
                                   'account.ownerId, ' +
                                   'account.owner.firstname,' +
                                   'account.owner.lastname,'+
                                   'account.recordtypeid, '+
                                   'account.recordtype.name,' +
                                   'account.type, ' +
                                   'Level_of_Effort__c,' +
                                   'Name, ' +
                                   'Ownerid, ' +
                                   'Owner.firstname, ' + 
                                   'Owner.lastname, ' +
                                   'Solution_Complexity__c, ' +
                                   'StageName, '+
                                   'Annualized_Revenue__c,' +
                                   'Amount, ' +
                                   'FTEs__c, ' +
                                   'TotalNumberofSeats__c ' +                                
                                   'FROM Opportunity';        
        ID batchprocessid = Database.executeBatch(bj);

        Test.stopTest();
   
       }


	public static void testBatch() 
	     {
	        List<Opportunity_Snapshot__c> testSnaplist = new List<Opportunity_Snapshot__c>();
        
            Opportunity_Snapshot__c testSnap = new Opportunity_Snapshot__c();
		    for(Integer i = 0 ; i < 200; i++){
		        testSnap.Ss_Account_Id__c                       = 'ID123425'+i;
                testSnap.Ss_Account_Industry__c                 = 'Offshoring and Nearshoring Test';
                testSnap.Ss_Account_Name__c                     = 'Test Account Name'+i;
                testSnap.Ss_Account_Owner_Id__c                 = 'Account Owner Test '+i;
                testSnap.Ss_Account_Owner_Name__c               = 'Test J Tester '+i*157469;
                testSnap.Ss_Account_Recordtype_Id__c            = 'Record Type Id123456789012345678901234567890123456789' +i;
                testSnap.Ss_Account_Recordtype_Name__c          = 'Record Type Name ' +i;
                testSnap.Ss_Account_Type__c                     = 'Account Prospect '+i;
                testSnap.Ss_Opportunity_Amount__c               =  451+i;
                testSnap.Ss_Opportunity_Annualized_Revenue__c   = 12+i;
                testSnap.Ss_Opportunity_Level_of_Effort__c      = 26+i;
                testSnap.Ss_Opportunity_Name__c                 = 'Test Opportunity Name ' +i;
                testSnap.Ss_Opportunity_Owner_Id__c             = 'Opportunity Owner Test ID'+i;
                testSnap.Ss_Opportunity_Owner_Name__c           = 'Sammy the Tester';
                testSnap.Ss_Opportunity_Solution_Complexity__c  = 'High';
                testSnap.Ss_Opportunity_Stage_Name__c           = 'Test Opportunity Stage ' +i;
                testSnap.Ss_Opportunity_Total_FTE__c            = 12;
                testSnap.Ss_Opportunity_Total_Seats__c          = 37;    
            
                testSnaplist.add(testSnap);

		}

		insert testSnaplist;
	   
		Test.StartTest();
               MyBatchJob bj2 = new MyBatchJob();
        
		ID batchprocessid = Database.executeBatch(bj2);
		   
		Test.StopTest();
		
		
	}
}
Your help is greatly appreciated.

Robert

 
I have received the below message when I tried to upload a Batch:

Database.Error[getFields=();getMessage=rC_Bios.Contact_AfterUpdate: execution of AfterUpdate caused by: System.ListException: Before Insert or Upsert list must not have two identically equal elements (rC_Bios) ;getStatusCode=CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY;]): method = updateContact

What is the best way to resolve this error message?

Thank you!

 
I have a trigger that I am trying to add a before update to a before insert trigger but i keep getting the following error.  What can I change on this code to make it allow insert and updates?

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger MarkPrimaryQuote caused an unexpected exception, contact your administrator: MarkPrimaryQuote: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0Q0n0000000DRrLCAW; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0Q0n0000000DRrL) is currently in trigger MarkPrimaryQuote, therefore it cannot recursively update itself: []: Trigger.MarkPrimaryQuote: line 19, column 1
 
//Created by Bob Poliquin 5/12/2016
// Updated the soql query to identify last modified date. 5/12/2016

trigger MarkPrimaryQuote on Quote (before insert,before update) {
    List<Datetime> oracleQuoteList = new List<Datetime>();
    for(Quote qRec : Trigger.new) {
   
        qRec.Primary_Quote__c = true;
        oracleQuoteList.add(qRec.LastModifiedDate);      
    }
    
    
    List<Quote> quoteListToUpdate = new List<Quote>();
    for(Quote qRec : [SELECT id,Primary_Quote__c,CreatedDate from Quote WHERE LastModifiedDate = TODAY AND HOUR_IN_DAY(LastModifiedDate) > 1]) {
        qRec.Primary_Quote__c =false;
        quoteListToUpdate.add(qRec);    
    }
         if(quoteListToUpdate != null && quoteListToUpdate .size() > 0) {
        update quoteListToUpdate;
    }
    
}

 
  • May 16, 2016
  • Like
  • 0
Please help!  I am still a novice when it comes to Apex.  I am trying to grab the last activity type and populate it on the lead.  The code is working however I am getting duplicate value errors a few times a day and I would like to clean up my code so that doesn't continue to happen.

Can someone take a look and help me out?
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
trigger LastActivityType on Task (after insert,before update) {
 
 Set<Id> LeadIds = new Set<Id>();
 List<Lead> LeadList = new List<Lead>();

for(Task t :trigger.new)
    {
  if(t.whoId!=null)
  {
        Schema.SObjectType tType= t.whoId.getSObjectType();
        if(tType == Lead.Schema.SObjectType)
        {
            LeadIds.add(t.WhoId);
        }
    }
  }
    {
  //Querying the related Lead based on whoId on Task
  Map<Id,Lead> LeadMap =  new Map<Id,Lead>([select id,Last_Activity_Type__c from Lead where id in:LeadIds]);
  
  for(Task t :Trigger.new)

    for(Lead l : LeadMap.Values())
    {
      l.Last_Activity_Type__c = t.Type;
      LeadList.add(l);
    }
  }
  // updating the Lead
  if(LeadList.size()>0)
  {
    update LeadList;
  }
}

Thank you in advance!
I am new to the Apex and am see if someone can help me understand how I go about testing a method that gets its data from a List that is an sObject when the parameter that I pass in is the String of the query. I am having trouble figuring out how to get the execute method to test successfully.

The following is my Apex Batchable Class:
 
global class MyBatchJob implements Database.Batchable<sObject>{

    global string query;

       
    global MyBatchJob(){
        String query = 'SELECT      account.id, ' +
                                   'account.name, ' +
                                   'account.industry, ' +
                                   'account.ownerId, ' +
                                   'account.owner.firstname,' +
                                   'account.owner.lastname,'+
                                   'account.recordtypeid, '+
                                   'account.recordtype.name,' +
                                   'account.type, ' +
                                   'Level_of_Effort__c,' +
                                   'Name, ' +
                                   'Ownerid, ' +
                                   'Owner.firstname, ' + 
                                   'Owner.lastname, ' +
                                   'Solution_Complexity__c, ' +
                                   'StageName, '+
                                   'Annualized_Revenue__c,' +
                                   'Amount, ' +
                                   'FTEs__c, ' +
                                   'TotalNumberofSeats__c ' +                              
                                   'FROM Opportunity';     
    } 

    global Database.QueryLocator start(Database.BatchableContext BC){
        System.debug('Started the Batch job to copy key Opportunity Record fields.');
        System.debug('The current Batch unique identifier for this job is : '+ BC.getJobId());
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC,List<Opportunity> scope) {
        System.debug('Executed the Batch job to copy Opportunity Records.');
        System.debug('The current Batch unique identifier for this job is : '+ BC.getJobId());
        List<Opportunity_Snapshot__c> snapList = new List<Opportunity_Snapshot__c>();

                 //Assuming the snapshots you want are of Contact data
		        for(Opportunity opp: scope) {
                 //create a sObject NOT an sObject List to hold the data until I add to the List with snapList.add(snap)
                 //This is a lot like creating a JSON framework in Javascript
                    Opportunity_Snapshot__c snap = new Opportunity_Snapshot__c();
            
                    //start adding to the snap variable from the query results
                    snap.Ss_Account_Id__c                       = opp.AccountId;
                    snap.Ss_Account_Industry__c                 = opp.Account.Industry;
                    snap.Ss_Account_Name__c                     = opp.Account.Name;
                    snap.Ss_Account_Owner_Id__c                 = opp.Account.OwnerId;
                    snap.Ss_Account_Owner_Name__c               = opp.Account.Owner.Firstname + ' ' + opp.Owner.Lastname;
                    snap.Ss_Account_Recordtype_Id__c            = opp.account.recordtypeid;
                    snap.Ss_Account_Recordtype_Name__c          = opp.account.recordtype.name;
                    snap.Ss_Account_Type__c                     = opp.Account.Type;
                    snap.Ss_Opportunity_Amount__c               = opp.Amount;
                    snap.Ss_Opportunity_Annualized_Revenue__c   = opp.Annualized_Revenue__c;
                    snap.Ss_Opportunity_Level_of_Effort__c      = opp.Level_of_Effort__c;
                    snap.Ss_Opportunity_Name__c                 = opp.Name;
                    snap.Ss_Opportunity_Owner_Id__c             = opp.Ownerid;
                    snap.Ss_Opportunity_Owner_Name__c           = opp.Owner.firstname + ' ' + opp.Owner.lastname;
                    snap.Ss_Opportunity_Solution_Complexity__c  = opp.Solution_Complexity__c;
                    snap.Ss_Opportunity_Stage_Name__c           = opp.StageName;
                    snap.Ss_Opportunity_Total_FTE__c            = opp.FTEs__c;
                    snap.Ss_Opportunity_Total_Seats__c          = opp.TotalNumberofSeats__c;

                    //Let's now add these variables to the list to be inserted at the end of the loop.
                    snapList.add(snap); 
  
          
        } 
        insert snapList; 
   }

   global void finish(Database.BatchableContext BC) {
        System.debug(LoggingLevel.WARN,'Batch Job is Complete!!!!!');
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[]{'any@gmail.com', 'any@outlook.com'};
        mail.setToAddresses(toAddresses);
        mail.setSubject('Email Batch Worked');
        mail.setPlainTextBody ('Batch Job worked');
    }
}
So far I have 29% successfully tested.
 
@isTest
public class TestMyBatchJob {
    public static testmethod void TestBatchJob(){
        Test.startTest();
        MyBatchJob bj = new MyBatchJob();
        bj.query=      'SELECT      account.id, ' +
                                   'account.name, ' +
                                   'account.industry, ' +
                                   'account.ownerId, ' +
                                   'account.owner.firstname,' +
                                   'account.owner.lastname,'+
                                   'account.recordtypeid, '+
                                   'account.recordtype.name,' +
                                   'account.type, ' +
                                   'Level_of_Effort__c,' +
                                   'Name, ' +
                                   'Ownerid, ' +
                                   'Owner.firstname, ' + 
                                   'Owner.lastname, ' +
                                   'Solution_Complexity__c, ' +
                                   'StageName, '+
                                   'Annualized_Revenue__c,' +
                                   'Amount, ' +
                                   'FTEs__c, ' +
                                   'TotalNumberofSeats__c ' +                                
                                   'FROM Opportunity';        
        ID batchprocessid = Database.executeBatch(bj);

        Test.stopTest();
   
       }


	public static void testBatch() 
	     {
	        List<Opportunity_Snapshot__c> testSnaplist = new List<Opportunity_Snapshot__c>();
        
            Opportunity_Snapshot__c testSnap = new Opportunity_Snapshot__c();
		    for(Integer i = 0 ; i < 200; i++){
		        testSnap.Ss_Account_Id__c                       = 'ID123425'+i;
                testSnap.Ss_Account_Industry__c                 = 'Offshoring and Nearshoring Test';
                testSnap.Ss_Account_Name__c                     = 'Test Account Name'+i;
                testSnap.Ss_Account_Owner_Id__c                 = 'Account Owner Test '+i;
                testSnap.Ss_Account_Owner_Name__c               = 'Test J Tester '+i*157469;
                testSnap.Ss_Account_Recordtype_Id__c            = 'Record Type Id123456789012345678901234567890123456789' +i;
                testSnap.Ss_Account_Recordtype_Name__c          = 'Record Type Name ' +i;
                testSnap.Ss_Account_Type__c                     = 'Account Prospect '+i;
                testSnap.Ss_Opportunity_Amount__c               =  451+i;
                testSnap.Ss_Opportunity_Annualized_Revenue__c   = 12+i;
                testSnap.Ss_Opportunity_Level_of_Effort__c      = 26+i;
                testSnap.Ss_Opportunity_Name__c                 = 'Test Opportunity Name ' +i;
                testSnap.Ss_Opportunity_Owner_Id__c             = 'Opportunity Owner Test ID'+i;
                testSnap.Ss_Opportunity_Owner_Name__c           = 'Sammy the Tester';
                testSnap.Ss_Opportunity_Solution_Complexity__c  = 'High';
                testSnap.Ss_Opportunity_Stage_Name__c           = 'Test Opportunity Stage ' +i;
                testSnap.Ss_Opportunity_Total_FTE__c            = 12;
                testSnap.Ss_Opportunity_Total_Seats__c          = 37;    
            
                testSnaplist.add(testSnap);

		}

		insert testSnaplist;
	   
		Test.StartTest();
               MyBatchJob bj2 = new MyBatchJob();
        
		ID batchprocessid = Database.executeBatch(bj2);
		   
		Test.StopTest();
		
		
	}
}
Your help is greatly appreciated.

Robert

 
HI 

can any one help me out to Send an email to contacts related account owner through apex.

Thanks in advance
Okay, i have this trigger which seems to work for all of its intended purposes but occasionally we are getting a CPU Limit Exception.  I've noticed that we get the CPU Limi Exception while Marketo is trying to update the Lead Score.  Any thoughts?
trigger LeadTrigger on Lead (after insert, after update, before insert, before update) {
    
     if (!FollowUpTaskHelper.hasAlreadyCreatedFollowUpTasks()) {    
             FollowUpTaskHelper.setAlreadyCreatedFollowUpTasks();
         string stringfield = '';
         Lead LeadLog = new Lead();
    Set<Id> Taskids = new Set<Id>();
    Set<Id> CloseRelatedTaskIds = new Set<Id>();
    Set<Id> CloseRelatedTaskIds2 = new Set<Id>();
    Set<Id> ReassignTaskLeads = new Set<Id>();
    Set<Id> NothingTranspiredTaskIds = new Set<Id>();
    Set<Id> TrustIds = new Set<Id>();
	Map<Id,task> TasksToUpdate = new Map<Id,Task>();
	Map<Id,task> TasksToUpdate2 = new Map<Id,Task>();
    Map<Id,task> TasksToUpdateRA = new Map<Id,Task>();
    Map<Id,lead> LeadsToUpdate = new Map<Id,Lead>();
    Map<Id,lead> LeadsToUpdate2 = new Map<Id,Lead>();
    Task TaskLog = new Task();
    Task TaskLog2 = new Task();
 string thefield123 = '';
            string thefield1234 ='';
    List<Lead> ls = new List<Lead>();
    list<user> ldusers = [select id, name from user where name = 'marketo' OR name = 'Marketo' OR name = 'Brad Davis' OR name = 'brad davis' order by name];      
   
    for(lead a: trigger.new)
    {
        if(a.isconverted == false){
        
                if(ldusers.size() != 0){
        if(a.ownerid == ldusers[1].id){
            a.ownerid = ldusers[0].id;
        }
        if(a.ownerid ==ldusers[0].id){
        ls.add(new Lead(id = a.id));
        }
    }
 
  
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule = true;
    dmo.EmailHeader.triggerUserEmail = true;    
    Database.update(ls, dmo);        
      
        if( a.Close_All_Current_Marketo_Open_Tasks__c == true  )
        {
            a.Close_All_Current_Marketo_Open_Tasks__c = false;
            CloseRelatedTaskIds.add(a.Id);
        }
             CloseRelatedTaskIds2.add(a.Id);    
			leadstoupdate2.put(a.id, a);
        
    }
     }
         
         
    
    for(task t:[SELECT id, whoid, subject, ownerid from task WHERE (whoid in: CloseRelatedTaskIds AND status != 'completed') OR (whoid in: CloseRelatedTaskIds2 AND status != 'completed') limit 100]){
        if(CloseRelatedTaskIds.contains(t.whoId))	{
        if(t.subject.contains('marketo') || t.subject.contains('Marketo') || t.subject.contains('MARKETO')){
        taskstoupdate.put(t.Id, t);
        
            if(taskstoupdate.get(t.Id) != null){
            tasklog = TasksToUpdate.get(t.id);
            tasklog.status = 'completed';
            stringfield = tasklog.subject;
            
            tasklog.subject = tasklog.subject + 'Set by trigger ezwf';
            taskstoupdate.put(tasklog.Id,tasklog);    

           }
   }
    }
         if(CloseRelatedTaskIds2.contains(t.whoId))	{
         			taskstoupdate2.put(t.Id, t);
        
            if(taskstoupdate2.get(t.Id) != null){
            tasklog2 = TasksToUpdate2.get(t.id);
            LeadLog = leadstoupdate2.get(t.WhoId);    
            tasklog2.ownerid = Leadlog.ownerid;
            TasksToUpdate2.put(TaskLog2.Id,TaskLog2);   
           }
         }
        
    }


       
      if(taskstoupdate != null && taskstoupdate.values() != null &&taskstoupdate.values().size() > 0){
        update TasksToUpdate.values();
    } 
               if(taskstoupdate2 != null && taskstoupdate2.values() != null &&taskstoupdate2.values().size() > 0){
        update TasksToUpdate2.values();
    } 
FollowUpTaskHelper.setAlreadyCreatedFollowUpTasksFalse();
     }
    
}

 

I am trying to create a professional PDF document using standard APEX and HTML properties to create my content.

I am facing issue with the word-wrap property of CSS as it is misbehaving.

 

Let me explain

I am trying to display the contents of a field in a table (around 7 columns) and render it as pdf. Regardless of what I try, i cannot get the word-wrap to break the word so that the text does not go beyond the container.

 

Here is the code

<table class="tableStyle" >
<thead>
<tr>
<th width="5%" style="color:#FFFFFF;" align="center"><div id="inner">#</div></th>
<th width="30%" style="color:#FFFFFF;"><div id="inner">Field</div></th>
<th width="15%" style="color:#FFFFFF;"><div id="inner">Type</div></th>
<th width="30%" style="color:#FFFFFF;"><div id="inner">Values</div></th>
<th width="10%" style="color:#FFFFFF;"><div id="inner">Default Value</div></th>
<th width="10%" style="color:#FFFFFF;" align="center"><div id="inner">Track History</div></th>
</tr>
</thead>
<tbody>
<apex:repeat value="{!customObject.fields}" var="field">
<tr>
<td width="5%" align="center"><div id="inner">{!FLOOR(count)}</div></td>
<td width="30%"><div id="inner">{!field.label} ({!field.fullName})</div></td>
<td width="15%"><div id="inner">{!field.type}</div></td>
<td width="30%">
<div id="inner">
<apex:repeat value="{!field.values}" var="value">
{!value}<BR/>
</apex:repeat>
</div>
</td>
<td width="10%"><div id="inner">{!field.defaultValue}</div></td>
<td width="10%" align="center">
<div id="inner">
<apex:image value="{!URLFOR($Resource.DesignDocument, IF(field.trackHistory, 'images/checkbox/checkbox_checked.gif', 'images/checkbox/checkbox_unchecked.gif'))}"/>
</div>
</td>
<apex:variable var="count" value="{!count+ 1}"/>
</tr>
</apex:repeat>
</tbody>
</table>

 

and here is the css
table.tableStyle {
width: 100%;
border-collapse: collapse;
background-color: white;
cellpadding:0.5em;
table-layout: fixed;
}
#inner {
border-width: 0em;
margin: 0em;
word-wrap: break-word;
overflow: inherit;
}
td, tr, th{
font-family: Calibri, Arial, Helvetica, sans-serif;
font-size: 0.9em;
color:#000000;
align: left;
vertical-align: top;
word-wrap: break-word;
overflow:hidden;
}

 

Here is the kicker -
When I render this table in visualforce as pdf, the content overflows and gets clipped (due to overflow:hidden) if i dont specify the overflow:hidden property, it spills over in the next <td> block

 

But when i take the renderas pdf away from the page, the content wraps properly. Could you tell me how to resolve this issue?

 
We have a few VF pages rendered as PDF which are using <Apex: dataTable>. This document is genereated in protrait size with 8 columns. It also include Product Name (80 char).
 
I want the text to be wrapped in each column. If I render the page as HTML then it works, but it does not work for PDF. I am even specifying the columnsWidth attribute.
 
 
Code:
<apex:dataTable width="100%" border="0" id="DataTable" value="{!SalesOrderLines}" var="SalesOrderLine" style="font-size:10px;vertical-align:top;word-wrap: break-word;"  headerClass="headerrow" 
   columnsWidth="60,250,90,50,95,100,100,100" rowclasses="odd,even" >


 <apex:column headervalue="Line">
             <apex:outputField value="{!SalesOrderLine.Name}"/>
 </apex:column>   
 <apex:column style="width: 200px;word-wrap:break-word" >
     <apex:facet name="header">
 {!$ObjectType.SalesOrderLine__c.Fields.Product__c.label}                                 
      </apex:facet>
        {!IF(SalesOrderLine.Product__r.name = null,SalesOrderLine.Product__c, SalesOrderLine.Product__r.name)}
 </apex:column> 
.......
</apex:dataTable>

 I have even tried putting following style for <td> in the page
 
Code:
<style type="text/css">
  td {
    word-wrap: break-word;
  }
</style>

 
Does anyone has any idea, what is the best way to achieve word wraping for PDFs. This is very urgent !!!
 

 
 
I also
  • October 26, 2008
  • Like
  • 0