• KunalSharma
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 10
    Replies

Hi,

 

I am trying to render a VF page as a PDF, but I am getting the "PDF generation failed. Check the page markup is valid." error. The code is working fine in one enviroment but it is throwing the error in other. I know there was an issue with Salesforce summer release in 2012. Is this happening again with anyone else. PFB the code for VF page:

 

<apex:page controller="RSS_FormController" showHeader="false" renderAs="pdf"  sidebar="false" contentType="application/pdf#abcd.pdf">
<head>

<style> 
body
{
font-family: Arial, Helvetica, sans-serif;
{!if(RSSForm.Published__c,'',' background-image:url(/resource/jquery119/jquery-ui-1.10.2.custom/Draft.jpg);
            //background-repeat: no-repeat;
            background-position: center;
            width: 100%;')}
}
@page {
  size: A4;
  margin: 10%;
  //align: left;
  text-align: justify;
  
  @top-center {
        background-image: url(/resource/jquery119/jquery-ui-1.10.2.custom/logo_color.jpg) ;
        background-repeat: no-repeat;
        background-position:right top;
        width: 100%;
        //height: 50%;
        white-space: pre;
        content: "\00000a {!Day(DateValue(Now()))}-{!CASE( MONTH(DateValue(Now())) , 1, "January", 2, "February", 3, "March", 4, "April", 5, "May", 6, "June", 7, "July", 8, "August", 9, "September", 10, "October", 11, "November", 12, "December", "None")}-{!Year(DateValue(Now()))}";
        font-family: Arial, Helvetica, sans-serif;
        Font-Size:11px;
     } 
 

 

  @bottom-left {
     white-space: pre;
     content: "{!RSSform.Name} V.{!RSSform.Version__c} - {!RSSForm.Owner.Name}"   " \00000a abc Technologies, Inc.";
     font-family: Arial, Helvetica, sans-serif;
     Font-Size:11px;
  }
 
  @bottom-right {
    white-space: pre;
    content: "Page " counter(page)  "\00000a Proprietary and Confidential";
    font-family: Arial, Helvetica, sans-serif;
    Font-Size:11px;
  }
}
.ProductFormTOC
{
Font-Size:13px;
}
a
{
text-decoration:none;
color:black;
}
.SectionsTOC
{
list-style-type: none;
}
.ProductFormName
{
color:#38608F;
Font-Size:18px;
Font-weight:bold;
padding-bottom:8px;
}
.SectionName
{
color:#38608F;
Font-Size:16px;
}
.Question
{
Font-Weight:bold;
Font-Size:12px;
}
.Response
{
Font-Size:12px;
//text-align: justify;
}
.contents
{
Font-Size:12px;
page-break-after:always;
}
</style>
</head>  

<body>

<div >
<center><label style="Font-Size:22px;Font-weight:bold;">{!RSSform.Name}</label>
<br/>
Version :{!RSSform.Version__c}
</center>

<br/>
<br/>
<br/>
<div>
<label style="color:#38608F;Font-Size:18px;Font-weight:bold;"> Contents</label>
</div>
<br/>
<div class="contents">
<apex:repeat value="{!RSSFormWrappers}" var="rfw">   

&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Form{!rfw.UniqueNumber}" class="ProductFormTOC"><apex:outputLabel value="{!rfw.ProductForm.Survey__r.Name}"></apex:outputLabel></a>
<ul class="SectionsTOC">
<apex:repeat var="g" value="{!rfw.responseGroupWrappers}">
<li>
<a href="#Group{!g.UniqueNumber}"><apex:outputLabel value="{!g.questionGroup.Name}" ></apex:outputLabel></a>
</li>
</apex:repeat>
</ul>


</apex:repeat>
</div>
<apex:repeat value="{!RSSFormWrappers}" var="rfw">   
<div id="Form{!rfw.UniqueNumber}" style="page-break-after:always;"  >
<div  class="ProductFormName"><apex:outputLabel value="{!rfw.ProductForm.Survey__r.Name}" ></apex:outputLabel>
</div>
<br/>
<apex:repeat var="g" value="{!rfw.responseGroupWrappers}">

<div id="Group{!g.UniqueNumber}">
<div style="padding-bottom: 5px;"><apex:outputLabel value="{!g.questionGroup.Name}" styleClass="SectionName" ></apex:outputLabel></div>
<apex:repeat var="r" value="{!g.surveyResponses}">

                    
                    <div >
                                                
                        <apex:outputLabel value="{!r.response.Survey_Question__r.Question__c}" styleClass="Question"></apex:outputLabel> 
                    </div>
                    
                   <div style="text-align: justify;">
                        <apex:outputLabel value=" {!if(r.response.Response__c='','--No Answer--',r.response.Response__c)}" styleClass="Response" rendered="{! OR(IF(r.response.Survey_Question__r.Type__c = 'Multi-Select--Vertical',false,true),
                        if(r.response.Response__c='',true,false))}"></apex:outputLabel>
                   </div> <br/>
                   
                   <div Id='checkBox' rendered="{! AND(IF(r.response.Survey_Question__r.Type__c = 'Multi-Select--Vertical',true,false), IF(r.response.Response__c='',False,True))}">
                       <apex:repeat var="selectedItem" value="{! r.CheckBoxValues}">
                           <apex:outputLabel value="{! selectedItem}" styleClass="Response" rendered="{! AND(IF(r.response.Survey_Question__r.Type__c = 'Multi-Select--Vertical',true,false), IF(r.response.Response__c='',False,True))}"></apex:outputLabel> <br/>
                       </apex:repeat>    
                   </div>
                   
                   <!--div  rendered="{! IF(r.response.Survey_Question__r.Type__c = 'Free Text',true,false)}">
                       <apex:outputLabel value="{! IF(r.response.Response__c='','--No Answer--','hh')}" rendered="IF(r.response.Response__c='',true,false"></apex:outputLabel>
                       <apex:outputLabel value="{! r.answer}"></apex:outputLabel>
                   </div-->
                   
                   <!--apex:repeat var="response" value="{! pdftempMap[r.response.Survey_Question__r.Id]}"></apex:repeat>
                   <apex:outputLabel value="response"></apex:outputLabel--> 
                    
</apex:repeat>
</div>
</apex:repeat>
</div>
</apex:repeat>

</div>

</body>
</apex:page>

 

Thanks,

Kunal

This code auto-creates OLI when a user create a new opportunity and selet a product name from the custome picklist (product__C).

I need to deploy this to our production instance, but I don't know how to write test code for this..

Please, help me.. I need to deploy this as soon as possible.


trigger AutoCreateProduct on Opportunity (after insert) { 
    List<OpportunityLineItem> OpportunityLineItems = new List<OpportunityLineItem>(); 
    for (Opportunity newOpportunity: Trigger.New) { 
        if(newOpportunity.product__C.equalsIgnoreCase('CRA')){
            OpportunityLineItems.add(new OpportunityLineItem(OpportunityId = newOpportunity.Id,PricebookEntryId ='01u61000001a8iVAAQ',Quantity = newopportunity.volume__C,UnitPrice = newopportunity.Sales_Price__C)); 
        } if (newOpportunity.product__C.equalsIgnoreCase('GALV')){
            OpportunityLineItems.add(new OpportunityLineItem(OpportunityId = newOpportunity.Id,PricebookEntryId ='01u61000001a8iQAAQ',Quantity = newopportunity.volume__C,UnitPrice = newopportunity.Sales_Price__C)); 
        }
          if (newOpportunity.product__C.equalsIgnoreCase('2TFS')){
            OpportunityLineItems.add(new OpportunityLineItem(OpportunityId = newOpportunity.Id,PricebookEntryId ='01u61000001aBo7AAE',Quantity = newopportunity.volume__C,UnitPrice = newopportunity.Sales_Price__C)); 
        }
if (newOpportunity.product__C.equalsIgnoreCase('DRTP')){
            OpportunityLineItems.add(new OpportunityLineItem(OpportunityId = newOpportunity.Id,PricebookEntryId ='01u61000001aBoRAAU',Quantity = newopportunity.volume__C,UnitPrice = newopportunity.Sales_Price__C)); 
        }
    } 
    if(!OpportunityLineItems.isEmpty()){
        Database.SaveResult[] srList = Database.insert(OpportunityLineItems, false);

        // Iterate through each returned result
        for (Database.SaveResult sr : srList) {
            if (sr.isSuccess()) {
                // Operation was successful, so get the ID of the record that was processed
                System.debug('Successfully inserted Line Item. Oppty Prodcut ID: ' + sr.getId());
            }
            else {
                // Operation failed, so get all errors                
                for(Database.Error err : sr.getErrors()) {
                    System.debug('The following error has occurred.');                    
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                    System.debug('Opportunity Product fields that affected this error: ' + err.getFields());
                }
            }
        }
    }



Test code that has only 58% coverage.


@IsTest (seealldata=true)
public class AutoCreateProduct{
    public static testmethod void myunittest(){
               
       //create a dummy account
        Account a = new Account ();
        a.Name = 'Test Asset Account';
        insert a;
        
        //create a dummy opportunity
        Opportunity o = new Opportunity();
        o.AccountId = a.Id;
        o.Name = 'test Oppty';
        o.StageName = 'opportunity';
        o.CloseDate = system.today();
        o.product__c = 'cra';
        o.volume__c = 10;
                insert o;
  
    }
}
 
  • January 22, 2016
  • Like
  • 0
public  class AUditingBatch implements Database.Batchable<sObject>,Database.Stateful
{
public Database.querylocator start(Database.BatchableContext BC){

string query1='SELECT Id,Action,DelegateUser,CreatedBy.Name,CreatedDate,Display,Section FROM SetupAuditTrail';
return Database.getQueryLocator(query1);
    }
public void execute(Database.BatchableContext BC, List<SetupAuditTrail> scope )
    {
  List<AUditTrial__c> auditList= new List<AUditTrial__c>();//INTIALZE CUSTOM OBJECT
        for(SetupAuditTrail t : scope){ 
        AUditTrial__c AU= new AUditTrial__c(
                   Action__c = t.Action,
                   Name= t.CreatedBy.Name,
                   CreatedBy__c= t.CreatedBy.Name,
                   CreatedDate__c = t.CreatedDate,
                   DelegateUser__c= t.DelegateUser,
                   Display__c= t.Display,
                   Section__c= t.Section);
               auditList.add(AU);
        }
    insert auditList;
    }
public void finish(Database.BatchableContext BC)
{
    system.debug('capture the setup audit trial Data finished');
  }
}

test class


@isTest 
public class TestAudingbatch {
static Testmethod void  testAU(){ 
string query = 'Select Action__c,Display__c,Section__c, CreatedBy__c, CreatedDate__c, DelegateUser__c From AUditTrial__c';
 AUditTrial__c[] m1=new List<AUditTrial__c>();

for (integer i=0; i<10;i++)
{
AUditTrial__c a1=new AUditTrial__c(
Action__c ='apexclass',
Display__c='modified',
Section__c='pagelayout');
 m1.add(a1);
}
insert m1;
    Database.QueryLocator QL;
    Database.BatchableContext BC;
    List <SetupAuditTrail> setup=new List<SetupAuditTrail>();
    List<AUditTrial__c> Auditt = new List<AUditTrial__c>();
    test.startTest();
    AUditingBatch AU = new AUditingBatch();
    QL = AU.start(bc);
    AU.finish(BC);
   AU.execute(BC,setup);


    test.stopTest();
}

Is there a way to create a function that can take in a varying number of parameters? 

 

I know in java to do such a thing you can have a function like this: 

 

public double average(double...values) { 

 ....function body....

}

 

Is there a simliar method to do this in APEX? 

 

Thanks in advance! 

  • September 04, 2013
  • Like
  • 0

Hi folks..i am new to salesforce/visualforce/apex. I have created a custom object Deal__c and have created a button to search the deals based on the users input. I need to add the save button. Can someone plz show how to add?i tried creating a stnadard controller and using an extension. But it was showing constructor errror.Any help is greatly appreciated.

 

 

public with sharing class Demo2 {
    public List<Deal__c> SearchResult{get;set;}
    public String SelectedValue1{get;set;}
    public String SelectedValue2{get;set;}
    public Deal__c SearchCriteria{get;set;}
    
    public Demo2 ()
    {
        SearchCriteria = new Deal__c();
    }
    
    public void filterRecord()    
    {
        SearchCriteria = new Deal__c();
        SearchResult = new List<Deal__c>();
        
        SearchResult = [SELECT         Deal_Name__c,
                                    Deal_Type__c
                              FROM Deal__c
                              WHERE Deal_Name__c =: SearchCriteria.Deal_Name__c
                              AND Deal_Type__c    =: SearchCriteria.Deal_Type__c];
         if(SearchResult.size() == 0)
         {
            Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records to Display'));
         }
    }
    
       
}

 

<apex:page controller="Demo2">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection >
          <apex:inputField value="{!SearchCriteria.Deal_Name__c}"/>
      
          <apex:inputField value="{!SearchCriteria.Deal_Type__c}"/>
          
          <apex:commandButton value="Search" action="{!filterRecord}" reRender="applicantTbl,error"/>
          
          
      
  </apex:pageBlockSection>
 
      <apex:pageBlockTable styleClass="appTbl" id="applicantTbl" value="{!SearchResult}" var="rec">
          <apex:column value="{!rec.Deal_Name__c}"/>
          <apex:column value="{!rec.Deal_Type__c}"/>      
          <apex:outputLink value="{!URLFOR($Page.customDetailPage, '', [id=Deal__c.id])" />
 
      </apex:pageBlockTable>
           <apex:pageMessages id="error"></apex:pageMessages>
  </apex:pageBlock>
 
    </apex:form>
</apex:page>

 

 

  • September 03, 2013
  • Like
  • 0

Hi,

 

I am trying to render a VF page as a PDF, but I am getting the "PDF generation failed. Check the page markup is valid." error. The code is working fine in one enviroment but it is throwing the error in other. I know there was an issue with Salesforce summer release in 2012. Is this happening again with anyone else. PFB the code for VF page:

 

<apex:page controller="RSS_FormController" showHeader="false" renderAs="pdf"  sidebar="false" contentType="application/pdf#abcd.pdf">
<head>

<style> 
body
{
font-family: Arial, Helvetica, sans-serif;
{!if(RSSForm.Published__c,'',' background-image:url(/resource/jquery119/jquery-ui-1.10.2.custom/Draft.jpg);
            //background-repeat: no-repeat;
            background-position: center;
            width: 100%;')}
}
@page {
  size: A4;
  margin: 10%;
  //align: left;
  text-align: justify;
  
  @top-center {
        background-image: url(/resource/jquery119/jquery-ui-1.10.2.custom/logo_color.jpg) ;
        background-repeat: no-repeat;
        background-position:right top;
        width: 100%;
        //height: 50%;
        white-space: pre;
        content: "\00000a {!Day(DateValue(Now()))}-{!CASE( MONTH(DateValue(Now())) , 1, "January", 2, "February", 3, "March", 4, "April", 5, "May", 6, "June", 7, "July", 8, "August", 9, "September", 10, "October", 11, "November", 12, "December", "None")}-{!Year(DateValue(Now()))}";
        font-family: Arial, Helvetica, sans-serif;
        Font-Size:11px;
     } 
 

 

  @bottom-left {
     white-space: pre;
     content: "{!RSSform.Name} V.{!RSSform.Version__c} - {!RSSForm.Owner.Name}"   " \00000a abc Technologies, Inc.";
     font-family: Arial, Helvetica, sans-serif;
     Font-Size:11px;
  }
 
  @bottom-right {
    white-space: pre;
    content: "Page " counter(page)  "\00000a Proprietary and Confidential";
    font-family: Arial, Helvetica, sans-serif;
    Font-Size:11px;
  }
}
.ProductFormTOC
{
Font-Size:13px;
}
a
{
text-decoration:none;
color:black;
}
.SectionsTOC
{
list-style-type: none;
}
.ProductFormName
{
color:#38608F;
Font-Size:18px;
Font-weight:bold;
padding-bottom:8px;
}
.SectionName
{
color:#38608F;
Font-Size:16px;
}
.Question
{
Font-Weight:bold;
Font-Size:12px;
}
.Response
{
Font-Size:12px;
//text-align: justify;
}
.contents
{
Font-Size:12px;
page-break-after:always;
}
</style>
</head>  

<body>

<div >
<center><label style="Font-Size:22px;Font-weight:bold;">{!RSSform.Name}</label>
<br/>
Version :{!RSSform.Version__c}
</center>

<br/>
<br/>
<br/>
<div>
<label style="color:#38608F;Font-Size:18px;Font-weight:bold;"> Contents</label>
</div>
<br/>
<div class="contents">
<apex:repeat value="{!RSSFormWrappers}" var="rfw">   

&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Form{!rfw.UniqueNumber}" class="ProductFormTOC"><apex:outputLabel value="{!rfw.ProductForm.Survey__r.Name}"></apex:outputLabel></a>
<ul class="SectionsTOC">
<apex:repeat var="g" value="{!rfw.responseGroupWrappers}">
<li>
<a href="#Group{!g.UniqueNumber}"><apex:outputLabel value="{!g.questionGroup.Name}" ></apex:outputLabel></a>
</li>
</apex:repeat>
</ul>


</apex:repeat>
</div>
<apex:repeat value="{!RSSFormWrappers}" var="rfw">   
<div id="Form{!rfw.UniqueNumber}" style="page-break-after:always;"  >
<div  class="ProductFormName"><apex:outputLabel value="{!rfw.ProductForm.Survey__r.Name}" ></apex:outputLabel>
</div>
<br/>
<apex:repeat var="g" value="{!rfw.responseGroupWrappers}">

<div id="Group{!g.UniqueNumber}">
<div style="padding-bottom: 5px;"><apex:outputLabel value="{!g.questionGroup.Name}" styleClass="SectionName" ></apex:outputLabel></div>
<apex:repeat var="r" value="{!g.surveyResponses}">

                    
                    <div >
                                                
                        <apex:outputLabel value="{!r.response.Survey_Question__r.Question__c}" styleClass="Question"></apex:outputLabel> 
                    </div>
                    
                   <div style="text-align: justify;">
                        <apex:outputLabel value=" {!if(r.response.Response__c='','--No Answer--',r.response.Response__c)}" styleClass="Response" rendered="{! OR(IF(r.response.Survey_Question__r.Type__c = 'Multi-Select--Vertical',false,true),
                        if(r.response.Response__c='',true,false))}"></apex:outputLabel>
                   </div> <br/>
                   
                   <div Id='checkBox' rendered="{! AND(IF(r.response.Survey_Question__r.Type__c = 'Multi-Select--Vertical',true,false), IF(r.response.Response__c='',False,True))}">
                       <apex:repeat var="selectedItem" value="{! r.CheckBoxValues}">
                           <apex:outputLabel value="{! selectedItem}" styleClass="Response" rendered="{! AND(IF(r.response.Survey_Question__r.Type__c = 'Multi-Select--Vertical',true,false), IF(r.response.Response__c='',False,True))}"></apex:outputLabel> <br/>
                       </apex:repeat>    
                   </div>
                   
                   <!--div  rendered="{! IF(r.response.Survey_Question__r.Type__c = 'Free Text',true,false)}">
                       <apex:outputLabel value="{! IF(r.response.Response__c='','--No Answer--','hh')}" rendered="IF(r.response.Response__c='',true,false"></apex:outputLabel>
                       <apex:outputLabel value="{! r.answer}"></apex:outputLabel>
                   </div-->
                   
                   <!--apex:repeat var="response" value="{! pdftempMap[r.response.Survey_Question__r.Id]}"></apex:repeat>
                   <apex:outputLabel value="response"></apex:outputLabel--> 
                    
</apex:repeat>
</div>
</apex:repeat>
</div>
</apex:repeat>

</div>

</body>
</apex:page>

 

Thanks,

Kunal

Hi All,

 

Last 2 days i am scratching my head to find a solution for generating dynamic tabs in a visual force page from controller class.

 

Here is the code , this is not optimized i wrote it just for learning. 

 

VF Page:

 

<apex:page sidebar="false" controller="TopOpportunityController" >
<apex:form >
<apex:commandButton value="New" action="{!updateNumberOfTabs}" reRender="DynamicTabs"/>
<apex:pageBlock id="DynamicTabs" title="Dynamic Tab Demo"  >
<apex:pageblockSection >
<apex:pageBlockSectionItem >
<apex:dynamicComponent componentValue="{!tabs}"/>
</apex:pageBlockSectionItem>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 And the controller for the above code is :

public with sharing class TopOpportunityController {
public string str{get;set;}
public class caseWrapper
{
    public String Description{get;set;}
    public String Status{get;set;}
}
public caseWrapper c{get;set;}
List<caseWrapper> caseWrp{get;set;}

public static Component.Apex.tabPanel p= new Component.Apex.tabPanel();
public Integer numberofTabs;
    public TopOpportunityController() 
    {
        
        //p = new Component.Apex.tabPanel();
        c = new caseWrapper();
        numberofTabs =1;
        caseWrp = new List<caseWrapper>();
        /*ADDING ONE TAB BY DEFAULT*/
         p.selectedTab='tab'+numberofTabs;         
         Component.Apex.tab tab1 = new Component.Apex.tab();
         tab1.switchType = 'client';
         tab1.name= 'tab'+1;
         tab1.label= 1+'-Tab';
         tab1.id = 'tab'+1;
         Component.Apex.CommandButton command = new Component.Apex.CommandButton();
         command.value='Save';
         command.expressions.action='{!save}';
         tab1.childComponents.add(command);
         Component.Apex.outputText f = new Component.Apex.outputText();
         f.value = 'Description';
         tab1.childComponents.add(f);
         Component.Apex.InputText t = new Component.Apex.InputText();
         t.expressions.value ='{!c.status}' ;
         tab1.childComponents.add(t);
         p.childComponents.add(tab1);      
         caseWrp.add(c);
    }

public void updateNumberOfTabs()
{
    numberofTabs++;
    caseWrapper c = new caseWrapper();
    //p.selectedTab='tab';         
    Component.Apex.tab tab1 = new Component.Apex.tab();
    tab1.switchType = 'client';
    tab1.name= 'tab'+numberofTabs;
    tab1.label= numberofTabs+'-Tab';
    tab1.id = 'tab'+numberofTabs;
    Component.Apex.CommandButton command = new Component.Apex.CommandButton();
    command.value='Save';
    command.expressions.action='{!save}';
    tab1.childComponents.add(command);
    Component.Apex.outputText f = new Component.Apex.outputText();
    f.value = 'Description';
    tab1.childComponents.add(f);
    Component.Apex.InputText t = new Component.Apex.InputText();
    t.expressions.value ='{!c.status}' ;
    tab1.childComponents.add(t);
    System.debug('------------------>'+p.childComponents);
    p.childComponents.add(tab1);
    System.debug('>>>>>>>>>>>>>>>>>>'+p.childComponents);       
    caseWrp.add(c);
}

public Component.Apex.tabPanel gettabs()
{
    
    return p;
}

public void save(){ 
System.debug('-------------'+caseWrp);
}

}

 let me expalin a bit here 

 

I am able to display the first tab in the visual force page and when i click on new button the controller should add another tab to the exsting page but not happening. instead it overwriting the existing tab.

 

The variable p in the controller is declared as static and when i update the variable with another tab, the old values is getting wiped out from it.(i think thats how static variable works, please let me know if i am wrong). Also i tried making it as a transient variable but updating the variable in the update method in the controller says "Attempt to de reference a null object".

 

Please help me out here. And teach me if my concept of transient and static variables are wrong.

 

I just wanted to display a new tab when i click on new button, also the field value i am entering in the tab fields i should get inn the controller wrapper class.

 

Thanks in advance

George Thomas

  • September 02, 2013
  • Like
  • 0

Hello all, I have a checkbox in my visualforce page just like this :

<apex:inputCheckbox />

 I want to be able in my controller, to see whether or not the checkbox is checked. I am making a query that is based on the checkbox's state. For example. This is the state if the checkbox is not selected.

 

select name from foo__c where id = contactid 

 if the checkbox is selected, I want my query to be something like this

 

select name from foo__c where id IN :allContactIds

I'm stuck on this. Any help?

  • August 29, 2013
  • Like
  • 0