function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alex Kirby 8Alex Kirby 8 

Error Unknown Property Error Extension Controller

Hi All,

I am trying to generate a pdf on from a VF page and attach it to the opportunity.

I used a custom controller and tried to modify it for use as an extension controller as I don't want any user input. The pdf must be saved to the opp on a button click etc.

I think I am missing something from my controller as when I call the {!savepdf} method I am getting this error:

Error: Unknown property 'Credit_Check__cStandardController.savepdf'

Here is the controller:
 
public with sharing class PdfGeneratorController {

    Public final Credit_Check__c CC;    
    
    public PdfGeneratorController (ApexPages.StandardController 
                                       stdController) {
                                           this.CC= (Credit_check__c)stdController.getrecord();
                                           
                                             
}
  

  public PageReference savePdf1() {

    PageReference pdf = Page.Cvs_PDF;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',cc.Opportunity__r.accountid);

    // create the new attachment
    Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

    try {

        // returns the output of the page as a PDF
        body = pdf.getContent();

    // need to pass unit test -- current bug    
    } catch (VisualforceException e) {
        body = Blob.valueOf('Some Text');
    }

    attach.Body = body;
    // add the user entered name
    attach.Name = cc.name;
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = cc.Opportunity__r.accountid;
    insert attach;

    // send the user to the account to view results
    return new PageReference('/'+cc.Opportunity__r.accountid);

  }

}

In the VF page I am simply calling {!savepdf}

Any help is much appreciated.

Al

 
Best Answer chosen by Alex Kirby 8
Anoop yadavAnoop yadav
Hi,

Use commandLink instead of href.
Check the below link.
http://astreait.com/creating-hyperlinks-in-visualforce/

All Answers

Anoop yadavAnoop yadav
Hi,
In your controller method is "savePdf1()"
But you are calling "savePdf()"
Use the same method name on both the place.
Alex Kirby 8Alex Kirby 8
Thats a typo, my bad it doesn't work when they are both named the same
Anoop yadavAnoop yadav
Hi,
what error you are getting?
You should query "Opportunity__r.accountid" in your controller.
Alex Kirby 8Alex Kirby 8
The error I am getting is on my VF page:

Error: Unknown property 'Credit_Check__cStandardController.savepdf'

so I have a command button with action="{!savepdf}" but the above error flags when I try to save.
Anoop yadavAnoop yadav
Post your Visualforce page.
Alex Kirby 8Alex Kirby 8
I did use:

<center><a href="" action="{!savePDF}" Oncomplete= "closeWin()" Style="cursor:pointer;" class="metro">Finish</a></center>
 
Alex Kirby 8Alex Kirby 8
<apex:page standardController="Credit_Check__c" extensions="PdfGeneratorController" sidebar="false" showHeader="false">
<html>

<apex:stylesheet value="https://fonts.googleapis.com/css?family=Open+Sans:300,600,700"/>

<style>
html{
overflow-y: scroll;
overflow-x: hidden;
}
Body{
  //background: #f7f7f7 url({!URLFOR($Resource.CVS_Images,'cream_dust.png')});
}

    body, input, textarea
    {
        font-family: 'Open Sans', sans-serif;
        //line-height: 1.85em;
        color: #888;
        font-weight: 300;
        //margin-left:0cm;
        //margin-right:0cm;
        font-size: 17px;
        
    
    strong, b
    {
        font-weight: 600;
        color: #3e3e3e;
    }
    
    acc
    {
        font-weight: 600;
        color: Green;
    }
    
    Dec
    {
        font-weight: 600;
        color: Red;
    }
    
        
    h1, h2, h3, h4, h5, h6
    {
        color: #3e3e3e;
    }
    
        h1 a, h2 a, h3 a, h4 a, h5 a, h6 a
        {
            text-decoration: none;
            color: inherit;
        }
    
    h2, h3, h4, h5, h6
    {
        font-weight: 700;
    }
    
    h1
    {
        font-weight: 200;
        font-size: 35px;
        line-height: 1.5em;        
    }
    
        h1 strong
        {
            font-weight: 700;
            font-size: 40px;          
                      
        }
    
    em, i
    {
        font-style: italic;
    }
    
    
</style>

<style>
@-webkit-keyframes myanimation {
  from {
    left: 0%;
  }
  to {
    left: 50%;
  }
}

.checkout-wrap {
  color: #444;
  font-family: 'Open Sans', sans-serif;
  margin: 40px auto;
  max-width: 1200px;
  position: relative;
}

ul.checkout-bar {
  margin: 0 20px;
}
ul.checkout-bar li {
  color: #ccc;
  display: block;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 20px 14px 80px;
  position: relative;
}
ul.checkout-bar li:before {
  -webkit-box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
  box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
  background: #ddd;
  border: 2px solid #FFF;
  border-radius: 50%;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  left: 20px;
  line-height: 37px;
  height: 35px;
  position: absolute;
  text-align: center;
  text-shadow: 1px 1px rgba(0, 0, 0, 0.2);
  top: 4px;
  width: 35px;
  z-index: 999;
}
ul.checkout-bar li.active {
  color: #8bc53f;
  font-weight: bold;
}
ul.checkout-bar li.active:before {
  background: #8bc53f;
  z-index: 99999;
}
ul.checkout-bar li.visited {
  background: #ECECEC;
  color: #57aed1;
  z-index: 99999;
}
ul.checkout-bar li.visited:before {
  background: #57aed1;
  z-index: 99999;
}
ul.checkout-bar li:nth-child(1):before {
  content: "1";
}
ul.checkout-bar li:nth-child(2):before {
  content: "2";
}
ul.checkout-bar li:nth-child(3):before {
  content: "3";
}
ul.checkout-bar li:nth-child(4):before {
  content: "4";
}
ul.checkout-bar li:nth-child(5):before {
  content: "5";
}
ul.checkout-bar li:nth-child(6):before {
  content: "6";
}
ul.checkout-bar a {
  color: #57aed1;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
}

@media all and (min-width: 800px) {
  .checkout-bar li.active:after {
    -webkit-animation: myanimation 3s 0;
    background-size: 35px 35px;
    background-color: #8bc53f;
    background-image: -webkit-linear-gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);
    background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);
    -webkit-box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
    box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
    content: "";
    height: 15px;
    width: 100%;
    left: 50%;
    position: absolute;
    top: -50px;
    z-index: 0;
  }

  .checkout-wrap {
    margin: 40px auto;
  }

  ul.checkout-bar {
    -webkit-box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
    box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
    background-size: 35px 35px;
    background-color: #EcEcEc;
    background-image: -webkit-linear-gradient(-45deg, rgba(255, 255, 255, 0.4) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.4) 50%, rgba(255, 255, 255, 0.4) 75%, transparent 75%, transparent);
    background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, 0.4) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.4) 50%, rgba(255, 255, 255, 0.4) 75%, transparent 75%, transparent);
    border-radius: 15px;
    height: 15px;
    margin: 0 auto;
    padding: 0;
    position: absolute;
    width: 100%;
  }
  ul.checkout-bar:before {
    background-size: 35px 35px;
    background-color: #57aed1;
    background-image: -webkit-linear-gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);
    background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);
    -webkit-box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
    box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    content: " ";
    height: 15px;
    left: 0;
    position: absolute;
    width: 10%;
  }
  ul.checkout-bar li {
    display: inline-block;
    margin: 50px 0 0;
    padding: 0;
    text-align: center;
    width: 19%;
  }
  ul.checkout-bar li:before {
    height: 45px;
    left: 40%;
    line-height: 45px;
    position: absolute;
    top: -65px;
    width: 45px;
    z-index: 99;
  }
  ul.checkout-bar li.visited {
    background: none;
  }
  ul.checkout-bar li.visited:after {
    background-size: 35px 35px;
    background-color: #57aed1;
    background-image: -webkit-linear-gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);
    background-image: -moz-linear-gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);
    -webkit-box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
    box-shadow: inset 2px 2px 2px 0px rgba(0, 0, 0, 0.2);
    content: "";
    height: 15px;
    left: 50%;
    position: absolute;
    top: -50px;
    width: 100%;
    z-index: 99;
  }
}
</style>


<!--Lines-->
<style>
.Horizontal-line {
   width: 500px;
   height: 1px;
   background-color: #F0F0F0;
   margin: 20 Auto;
   position: relative;
   z-index: -200;
}
.Invis-Horizontal-line {
   width: 500px;
   height: 0px;
   background-color: #F0F0F0;
   margin: 30 Auto;
   position: relative;
   z-index: -200;
}
</style>


<style>
Header{
    font-family: 'Open Sans', sans-serif;
    font-weight: 300;
    font-size: 36px;
    height:58px;
}
Header Strong{
    font-weight: 700;
}


.container{
font-family: 'Open Sans', sans-serif;
font-size: 25px;
width: 20%; 
height:200px; 
margin: 0 auto;
//background-color:#FFA500 ;
}
input[type=checkbox].css-checkbox {
                            display:none;
                        }

                        input[type=checkbox].css-checkbox + label.css-label{
                            padding-left:39px;
                            height:34px; 
                            display:inline-block;
                            line-height:34px;
                            background-repeat:no-repeat;
                            background-position: 0 0;
                            font-size:14px;
                            vertical-align:middle;
                            cursor:pointer;
                            //display: block;
                        }

                        input[type=checkbox].css-checkbox:checked + label.css-label {
                            background-position: 0 -34px;
                        }
                        label.css-label {
                background-image:url(http://csscheckbox.com/checkboxes/u/csscheckbox_2b9fa4d4f85c32396cdd8a162e63d32b.png);
                -webkit-touch-callout: none;
                -webkit-user-select: none;
                -khtml-user-select: none;
                -moz-user-select: none;
                -ms-user-select: none;
                user-select: none;
            }
    Table{
    font-family: 'Open Sans', sans-serif;
    font-size: 25px;
    margin: 0 auto;
    }
    
    </style>


<style type="text/css">
.JaseClass {
    -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
    -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
    box-shadow:inset 0px 1px 0px 0px #ffffff;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f9f9f9), color-stop(1, #e9e9e9) );
    background:-moz-linear-gradient( center top, #f9f9f9 5%, #e9e9e9 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f9f9f9', endColorstr='#e9e9e9');
    background-color:#f9f9f9;
    -webkit-border-top-left-radius:6px;
    -moz-border-radius-topleft:6px;
    border-top-left-radius:6px;
    -webkit-border-top-right-radius:6px;
    -moz-border-radius-topright:6px;
    border-top-right-radius:6px;
    -webkit-border-bottom-right-radius:6px;
    -moz-border-radius-bottomright:6px;
    border-bottom-right-radius:6px;
    -webkit-border-bottom-left-radius:6px;
    -moz-border-radius-bottomleft:6px;
    border-bottom-left-radius:6px;
    text-indent:0;
    border:1px solid #dcdcdc;
    display:inline-block;
    color:#666666;
    font-family: 'Open Sans', sans-serif;
    font-size:15px;
    font-weight:bold;
    font-style:normal;
    height:50px;
    line-height:50px;
    width:100px;
    text-decoration:none;
    text-align:center;
    text-shadow:1px 1px 0px #ffffff;
}
.JaseClass:hover {
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #e9e9e9), color-stop(1, #f9f9f9) );
    background:-moz-linear-gradient( center top, #e9e9e9 5%, #f9f9f9 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#e9e9e9', endColorstr='#f9f9f9');
    background-color:#e9e9e9;
}.JaseClass:active {
    position:relative;
    top:1px;
}</style>


<style>
.metro {
  display: inline-block;
  padding: 10px;
  margin: 10px;
  background: #08C;
  background-position: 0 0;
  /* Font styles */
  color: white;
  //font-weight: bold;
  text-decoration: none;
}

.metro:hover { background: #0AF; }

.metro.three-d {
  position: relative;
  box-shadow: 
    1px 1px #53A7EA,
    2px 2px #53A7EA,
    3px 3px #53A7EA;
  transition: all 0.1s ease-in;
}

.metro.three-d:active { 
  box-shadow: none;
  top: 3px;
  left: 3px;
}

</style>



<center>  

<div class="checkout-wrap">
  <ul class="checkout-bar">

    <li class="visited first">
      <a href="https://c.cs15.visual.force.com/apex/Cvs_Checkstest?id={!Credit_Check__c.id}">Opportunity Selection</a>
    </li>

    <li class="previous visited">
    <a href="https://c.cs15.visual.force.com/apex/Cvs_Pols?id={!Credit_Check__c.id}">Credit Terms</a>
    </li>

    <li class="previous visited">Credit Check</li>

    <li class="previous visited">
    <a href="https://c.cs15.visual.force.com/apex/Cvs_Results?id={!Credit_Check__c.id}">Review</a>
    </li>

    <li class="active">Complete</li>

  </ul>
</div>

</center>


<br>
</br>
<br>
</br>



<center><img src="{!URLFOR($Resource.CVS_Images,'Picture2ShadowTrans.png')}" height="230" width="320"/></center>

<center><div class="Horizontal-line"></div></center>
<br>
<center>In order to be able to keep this credit check you must accept the generated record!</center>
</br>
<br><center><input type="checkbox" name="checkboxG1" id="checkboxG1" class="css-checkbox"/><label for="checkboxG1" class="css-label"/>I Accept</center></br>
<center><div class="Horizontal-line"></div></center>




<center><a href="" Onclick= "closeWin()" Style="cursor:pointer;" class="metro">Finish</a></center>

<script>
function closeWin() {
    {!savePDF};
    window.close();
}
</script>

<center><div class="Horizontal-line"></div></center>

<br></br>


<center>Digital PDF result certificate for record <strong>{!Credit_Check__c.name}</strong></center>

<br></br>

<center><iframe id="I1" name="I1" src="https://c.cs15.visual.force.com/apex/Cvs_PDF?id={!Credit_Check__c.id}" style="width: 850px; height: 263px">Your browser does not support inline frames or is currently configured not to display inline frames.</iframe></center>
            
<center><div class="Horizontal-line"></div></center>

<br>
</br>


</html>

</apex:page>
Anoop yadavAnoop yadav
Hi,

Use commandLink instead of href.
Check the below link.
http://astreait.com/creating-hyperlinks-in-visualforce/
This was selected as the best answer
Alex Kirby 8Alex Kirby 8
Excellent thank you, that has enabled the process to work and an item is attached to opportunity from my related object. A pdf is not actually being generated in the document a VFException is shown:


System.VisualforceException: SObject row was retrieved via SOQL without querying the requested field: Credit_Check__c.Opportunity__c

These fields are not in my controller but are in the VF Page, I removed this one and it just went to the next field and threw an error there.
Alex Kirby 8Alex Kirby 8
To clarify, these fields are in the PDF document.
Alex Kirby 8Alex Kirby 8
Also.. the pdf generates fine when used outside of the above process
Alex Kirby 8Alex Kirby 8
Hi All,

I have managed to pull the fields through to the PDF by adding the fields required for the PDF to a the visualforce page that the button is located on.

I am receiving an error relating to a field which is not in my pdf specifically or on the VF page.

Error below:

System.VisualforceException: common.apex.runtime.impl.ExecutionException: SObject row was retrieved via SOQL without querying the requested field: User.Name

Any help would be awesome as I am so close!

Thanks,

Alex
 
Alex Kirby 8Alex Kirby 8
Anoop yadav helped resolved the subject query so marked as BA, the secondary errors and exceptions I managed to resolve on my own.

Thanks