• TechSteve
  • NEWBIE
  • 25 Points
  • Member since 2011

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

I have a nuber of custom forms I need to print what you see on screen. But, if I print from my browser I only get half the width of the page and only a short piece of it not the full page (they are scrolling pages). When I try java script they all call the browser print so I get the same result.

Can anyone help with any ideas.

Tried renderAs PDF page but it is just a mess.

I have tried the following:

<script Language="Javascript">

function printit(){  
if (window.print) {
    window.print();  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}
</script>

<script Language="Javascript">  
var NS = (navigator.appName == "Netscape");
var VERSION = parseInt(navigator.appVersion);
if (VERSION > 3) {
    document.write('<form><input type=button value="Print this Page" name="Print" onClick="printit()"></form>');        
}
</script>

Short alternative.........

<SCRIPT LANGUAGE="JavaScript">
if (window.print) {
document.write('<form><input type=button name=print value="Print" onClick="window.print()"></form>');
}
</script>

Shorter alternative .........

<a href="javascript&colon;window.print()">Print this page</a>

Hi all, I have used the notes & Attachments related list in my VF page. I want to know if you can turn of the delete action that appears when you save a note.

Can you modify that action column?

 

Thanks Steve

Hi all, I have used a controller extension to get the last record created for an object. I can display the $object.name in an outputLabel but need to save it with the record on the current page. Can you assign a value to an inputfield automatically (but not as formula), I can't get it to?

I don't want to rely on the user copy and pasteing? is there a way of saving the label value into the record?

I need to do this in the page or controller and use variables to carry the values around as there are 9 possibilities as to what the name may be.

** Page Code fragment**

<apex:pageBlockTable value="{!IARs}" var="ss" rendered="False">   
                    <apex:column breakBefore="true" headerValue="input Specific Form"><apex:inputfield value="{!ProgressNote__c.Relobject__c}"></apex:inputfield></apex:column>
                </apex:pageBlockTable>
                <apex:pageBlockTable value="{!IARs}" var="ss" rendered="{!IAR}">   
                    <apex:column breakBefore="true" headerValue="Assessment Type"><apex:outputLabel >{!ProgressNote__c.Relobject__c}</apex:outputLabel></apex:column>
                </apex:pageBlockTable>
 
                <apex:pageBlockTable value="{!IARs}" var="ss" rendered="{!IAR}">   
                    <apex:column breakBefore="true" headerValue="Record Number"><apex:outputLabel value="{!ss.name}"/></apex:column>
                </apex:pageBlockTable>
                <apex:pageBlockTable value="{!IARs}" var="ss" rendered="true">   
                    <apex:column breakBefore="true" headerValue="Input Specific Record"><apex:inputfield value="{!ProgressNote__c.RelformRec__c}">{!ss.name}</apex:inputfield></apex:column>
                </apex:pageBlockTable>

 

** Controller **

public ApexPages.StandardSetController setiar {
        get {
                if(setiar == null){
                setiar = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT name From INS_Annual_Review__c
                        Where ClientID__c = :ApexPages.currentPage().getParameters().get('cid') Order By name DESC limit 1]));
                }
                    return setiar;
            }
            set;
    }
   
    public List<INS_Annual_Review__c> getIARs() {
         return (List<INS_Annual_Review__c>) setiar.getRecords();
         }

Thank you

 

Steve

HI all, I have a vf page which is passed information from a number of possible other pages in the url.

From this I can find the name field for the last record I just just created before coming to this page.

I can display that by creating a list in the extension controller and sort it DESC then limit it to 1 record.

Now on my new page I wish to create a second record which when saved. inputs that record number (name) with this new record so it can be retrieved and displayed as part of the new record in its own right.

I cannot copy it striaght RelDoc__c = object.name; as this give error objectfield to string.

I tried copy to integer first but similar error.

 

Anyone got any ideas?

Is there a way to determine the name value on the first page and pass that to the second as part of the save method. (I have it redirecting there already).

 

Thanks to all

Steve

Hi all, I have been developing a site in the sandbox which has unit testing code with between 70 - 92% code coverage with a calculated 78% average. I know this isn't a great job well done but it meets minimum requirements for now.

But then when I migrate it to the production environment, the live site, the validation check says it will fail to install with 0% code coverage. How can that be?

Why would it say that?

Do all classes have to exceed the 75% individually?

If any system.assert tests fail, would that cause my problem?

Has anyone got anything that will help me?

I have not got a clue as to why this is the case. Please some advice would be a god send!

 

Thanks in advance,

 

Steve

HI all, I am writing the test class for a page that checks a list of records and shows the newest 1 on the page.

It is giving me the coverage I need but failing the Highlighted test and I just can't find the reason.

PLEASE  Could anyone offer any sugguestions:-

 

Public static TestMethod void getSF36info()
    {
         
    // this builds the constructor for the controller which links this to the correct object
            SF36__c testrev = new SF36__c(SF36Client__c = '003R000000Y7Gw4',
                HQ10a1__c = True,HQ10a2__c = False,HQ10a3__c = False,HQ10a4__c = False,HQ10a5__c = False,
                HQ11a1__c = False,HQ11a2__c = True,HQ11a3__c = False,HQ11a4__c = False,HQ11a5__c = False,
                HQ11b1__c = False,HQ11b2__c = False,HQ11b3__c = True,HQ11b4__c = False,HQ11b5__c = False,
                HQ11c1__c = False,HQ11c2__c = False,HQ11c3__c = False,HQ11c4__c = True,HQ11c5__c = False,
                HQ11d1__c = False,HQ11d2__c = False,HQ11d3__c = False,HQ11d4__c = False,HQ11d5__c = True,
                HQ1a1__c = False,HQ1a2__c = True,HQ1a3__c = False,HQ1a4__c = False,HQ1a5__c = False);
                Insert testrev;

            ApexPages.StandardController stdController = new ApexPages.StandardController(testrev);
            SF36Ext SF = new SF36Ext(stdController);
         
              // **** build a test list *****
            List<SF36__c> Reviews = new List<SF36__c>{};
            for (Integer i = 0; i < 10; i++) {
                SF36__c revs = new SF36__c(SF36Client__c = '003R000000Y7Gw4' + i,
                HQ10a1__c = True,HQ10a2__c = False,HQ10a3__c = False,HQ10a4__c = False,HQ10a5__c = False,
                HQ11a1__c = False,HQ11a2__c = True,HQ11a3__c = False,HQ11a4__c = False,HQ11a5__c = False,
                HQ11b1__c = False,HQ11b2__c = False,HQ11b3__c = True,HQ11b4__c = False,HQ11b5__c = False,
                HQ11c1__c = False,HQ11c2__c = False,HQ11c3__c = False,HQ11c4__c = True,HQ11c5__c = False,
                HQ11d1__c = False,HQ11d2__c = False,HQ11d3__c = False,HQ11d4__c = False,HQ11d5__c = True,
                HQ1a1__c = False,HQ1a2__c = True,HQ1a3__c = False,HQ1a4__c = False,HQ1a5__c = False);
                Reviews.add(revs);
                }
            System.debug('Inserting list detail');
                insert Reviews;
            System.assertEquals(Reviews.size()>5, true); // List has multiple records
            System.assert(SF36__c.HQ10a3__c != null); // field has data
           
                  // **** Extract a record ***
            for(SF36__c tr:[SELECT name,SF36Client__c,
                HQ10a1__c,HQ10a2__c,HQ10a3__c,HQ10a4__c,HQ10a5__c,HQ11a1__c,HQ11a2__c,HQ11a3__c,HQ11a4__c,
                HQ11a5__c,HQ11b1__c,HQ11b2__c,HQ11b3__c,HQ11b4__c,HQ11b5__c,HQ11c1__c,HQ11c2__c,HQ11c3__c,
                HQ11c4__c,HQ11c5__c,HQ11d1__c,HQ11d2__c,HQ11d3__c,HQ11d4__c,HQ11d5__c,HQ1a1__c,HQ1a2__c,
                HQ1a3__c,HQ1a4__c,HQ1a5__c
                FROM SF36__c
                WHERE CreatedDate = TODAY and SF36Client__c = '003R000000Y7Gw44'
                ORDER By name DESC LIMIT 1]){
                testFalse = tr.HQ11c1__c; testTrue = tr.HQ11c4__c;}
               // **** test it has data ****
            System.assertEquals(testFalse, False);
            System.assertEquals(testTrue, True); 
           
            System.debug('list test if an old record exists no rid');
            List<SF36__c> revs = SF.getSF36info();
                system.assert(revs.size()>0);
    } 

 

****** Controller ******

    public ApexPages.StandardSetController setar {
        get {
        if (ApexPages.currentPage().getParameters().get('rid') == null) { // if no record number is in url open the newest one *******
            if(setar == null) {
                setar = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT name,HQ10a1__c,HQ10a2__c,HQ10a3__c,HQ10a4__c,HQ10a5__c,HQ11a1__c,HQ11a2__c,HQ11a3__c,HQ11a4__c,

HQ11a5__c,HQ11b1__c,HQ11b2__c,HQ11b3__c,HQ11b4__c,HQ11b5__c,HQ11c1__c,HQ11c2__c,HQ11c3__c,

HQ11c4__c,HQ11c5__c,HQ11d1__c,HQ11d2__c,HQ11d3__c,HQ11d4__c,HQ11d5__c,HQ1a1__c,HQ1a2__c,HQ1a3__c,

HQ1a4__c,HQ1a5__c,HQ2a1__c,HQ2a2__c,HQ2a3__c,HQ2a4__c,HQ2a5__c,HQ3a1__c,HQ3a2__c,HQ3a3__c,HQ3b1__c,

HQ3b2__c,HQ3b3__c,HQ3c1__c,HQ3c2__c,HQ3c3__c,HQ3d1__c,HQ3d2__c,HQ3d3__c,HQ3e1__c,HQ3e2__c,HQ3e3__c,

HQ3f1__c,HQ3f2__c,HQ3f3__c,HQ3g1__c,HQ3g2__c,HQ3g3__c,HQ3h1__c,HQ3h2__c,HQ3h3__c,HQ3i1__c,HQ3i2__c,

HQ3i3__c,HQ3j1__c,HQ3j2__c,HQ3j3__c,HQ4a1__c,HQ4a2__c,HQ4b1__c,HQ4b2__c,HQ4c1__c,HQ4c2__c,HQ4d1__c,

HQ4d2__c,HQ5a1__c,HQ5a2__c,HQ5b1__c,HQ5b2__c,HQ5c1__c,HQ5c2__c,HQ6a1__c,HQ6a2__c,HQ6a3__c,HQ6a4__c,

HQ6a5__c,HQ7a1__c,HQ7a2__c,HQ7a3__c,HQ7a4__c,HQ7a5__c,HQ7a6__c,HQ8a1__c,HQ8a2__c,HQ8a3__c,HQ8a4__c,

HQ8a5__c,HQ9a1__c,HQ9a2__c,HQ9a3__c,HQ9a4__c,HQ9a5__c,HQ9a6__c,HQ9b1__c,HQ9b2__c,HQ9b3__c,HQ9b4__c,

HQ9b5__c,HQ9b6__c,HQ9c1__c,HQ9c2__c,HQ9c3__c,HQ9c4__c,HQ9c5__c,HQ9c6__c,HQ9d1__c,HQ9d2__c,HQ9d3__c,

HQ9d4__c,HQ9d5__c,HQ9d6__c,HQ9e1__c,HQ9e2__c,HQ9e3__c,HQ9e4__c,HQ9e5__c,HQ9e6__c,HQ9f1__c,HQ9f2__c,

HQ9f3__c,HQ9f4__c,HQ9f5__c,HQ9f6__c,HQ9g1__c,HQ9g2__c,HQ9g3__c,HQ9g4__c,HQ9g5__c,HQ9g6__c,           HQ9h1__c,HQ9h2__c,HQ9h3__c,HQ9h4__c,HQ9h5__c,HQ9h6__c,HQ9i1__c,HQ9i2__c,HQ9i3__c,HQ9i4__c,HQ9i5__c,

HQ9i6__c,SF36Client__c,CreatedByid,CreatedDate
                    From SF36__c
            // find only records for the client you have picked, sort with Order By newest first then limit output to 1(show only last record).
                    Where SF36Client__c = :ApexPages.currentPage().getParameters().get('cid') Order By name DESC Limit 1]));
            }
            return setar;
          
        } else {         // if record number (rid) is in url load that record into page ************  
            if(setar == null) {          
                setar = new ApexPages.StandardSetController(Database.getQueryLocator(
                        [SELECT name,HQ10a1__c,HQ10a2__c,HQ10a3__c,HQ10a4__c,HQ10a5__c,HQ11a1__c,HQ11a2__c,HQ11a3__c,HQ11a4__c,

HQ11a5__c,HQ11b1__c,HQ11b2__c,HQ11b3__c,HQ11b4__c,HQ11b5__c,HQ11c1__c,HQ11c2__c,HQ11c3__c,

HQ11c4__c,HQ11c5__c,HQ11d1__c,HQ11d2__c,HQ11d3__c,HQ11d4__c,HQ11d5__c,HQ1a1__c,HQ1a2__c,HQ1a3__c,

HQ1a4__c,HQ1a5__c,HQ2a1__c,HQ2a2__c,HQ2a3__c,HQ2a4__c,HQ2a5__c,HQ3a1__c,HQ3a2__c,HQ3a3__c,HQ3b1__c,

HQ3b2__c,HQ3b3__c,HQ3c1__c,HQ3c2__c,HQ3c3__c,HQ3d1__c,HQ3d2__c,HQ3d3__c,HQ3e1__c,HQ3e2__c,HQ3e3__c,

HQ3f1__c,HQ3f2__c,HQ3f3__c,HQ3g1__c,HQ3g2__c,HQ3g3__c,HQ3h1__c,HQ3h2__c,HQ3h3__c,HQ3i1__c,HQ3i2__c,

HQ3i3__c,HQ3j1__c,HQ3j2__c,HQ3j3__c,HQ4a1__c,HQ4a2__c,HQ4b1__c,HQ4b2__c,HQ4c1__c,HQ4c2__c,HQ4d1__c,

HQ4d2__c,HQ5a1__c,HQ5a2__c,HQ5b1__c,HQ5b2__c,HQ5c1__c,HQ5c2__c,HQ6a1__c,HQ6a2__c,HQ6a3__c,HQ6a4__c,

HQ6a5__c,HQ7a1__c,HQ7a2__c,HQ7a3__c,HQ7a4__c,HQ7a5__c,HQ7a6__c,HQ8a1__c,HQ8a2__c,HQ8a3__c,HQ8a4__c,

HQ8a5__c,HQ9a1__c,HQ9a2__c,HQ9a3__c,HQ9a4__c,HQ9a5__c,HQ9a6__c,HQ9b1__c,HQ9b2__c,HQ9b3__c,HQ9b4__c,

HQ9b5__c,HQ9b6__c,HQ9c1__c,HQ9c2__c,HQ9c3__c,HQ9c4__c,HQ9c5__c,HQ9c6__c,HQ9d1__c,HQ9d2__c,HQ9d3__c,

HQ9d4__c,HQ9d5__c,HQ9d6__c,HQ9e1__c,HQ9e2__c,HQ9e3__c,HQ9e4__c,HQ9e5__c,HQ9e6__c,HQ9f1__c,HQ9f2__c,

HQ9f3__c,HQ9f4__c,HQ9f5__c,HQ9f6__c,HQ9g1__c,HQ9g2__c,HQ9g3__c,HQ9g4__c,HQ9g5__c,HQ9g6__c,           HQ9h1__c,HQ9h2__c,HQ9h3__c,HQ9h4__c,HQ9h5__c,HQ9h6__c,HQ9i1__c,HQ9i2__c,HQ9i3__c,HQ9i4__c,HQ9i5__c,

HQ9i6__c,SF36Client__c,CreatedByid,CreatedDate
                    From SF36__c
                // find only records for the client you have picked, sort with Order By newest first then limit output to 1(show only last record).
                    Where SF36Client__c = :ApexPages.currentPage().getParameters().get('cid')
                    AND SF36__c.name = :ApexPages.currentPage().getParameters().get('rid')]));                      
            }
            return setar;
        }}
        set;
    }

    // Initialize setar and return a list of records read by the SWA call and the field name you want to see..
  
    public List<SF36__c> getSF36info() {
         return (List<SF36__c>) setar.getRecords();
    }

Hi all, needed to have a page redirect on save and achieved it with

 

public PageReference saveandnotes() {
          stdCtrl.save(); // This takes care of the details for you.
          PageReference pn = Page.PN;
          pn.getParameters().put('cid',ApexPages.currentPage().getParameters().get('cid'));
          pn.getParameters().put('form','OTReview__c');
          pn.setRedirect(true);
       return pn;
    }  

Trying now to write the unit test for it and getting no were fast. Got 70% cover overal just need this I think. So far i tried this but get the error

Compile Error: Method does not exist or incorrect signature: controller.saveandnotes() with 

Public Static TestMethod void saveandnotes()
        {
            // this builds the constructor for the controller which links this to the correct object
            OTReview__c testrev = new OTReview__c(OTLims1__c = 'abc', OTDiag__c = 'notlob', OTCognition__c = 'wife & kids',
                OTMental__c = 'can talk', OTPhysical__c = 'make tea', OTSensation__c = '50mg', OTMed__c = 'asprin',
                OTSafe__c = 'Yes');
                Insert testrev;

            ApexPages.StandardController stdController = new ApexPages.StandardController(testrev);
            OTRevConedit ARed = new OTRevConedit(stdcontroller);
           
            ApexPages.CurrentPage().getParameters().put('cid', '003R000000Y7Gw4');
            ApexPages.CurrentPage().getParameters().put('form', 'OTReview__c');
            String nextPage = controller.saveandnotes().getUrl();

            system.assertEquals('/apex/PN?cid=003R000000Y7Gw4', nextPage);

        }

  Any help would by appreciated emmensely.

Thanks

 

Steve

HI, New to this so treat me as dumb. Writing a unit test class for a very small class but keep getting this message

Error: Compile Error: Constructor not defined: [attachmentsample].<Constructor>()  yet I used the same format in another test and it doesn't complain! what is missing? cant see the wood for the tree's i think.

** class **

public class attachmentsample {

    public attachmentsample(ApexPages.StandardController controller) {

    }
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
  
    Public Pagereference Savedoc()
    {
        String accid = System.currentPagereference().getParameters().get('id');

        Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
        
         /* insert the attachment */
         insert a;
        return NULL;
    }  

}

** controller **

public class attachmentsampleTest {

    public static void attachmentsampleTest(ApexPages.StandardController controller) {
        PageReference pageRef = Page.attachment;
        test.setCurrentPage(pageRef);
        ApexPages.CurrentPage().getParameters().put('id', '003R000000Y7Gw4');

        attachmentsample atsam = new attachmentsample();
       
        controller.myfile.name = 'testdoc';
        controller.myfile.body = 'testing 123';
      
    }
}

Please I am really under pressure to get this stuff working but keep going round in circles.

Thanks

Steve.

 

 

Hi all, development in the sandbox doesn't need the testing so been busy developing. The assessment controller is stand alone with no object just a page with direction and display controls. I know I am a pain but could someone help please? with comments please as I am very new. ?

Here's my code so far giving me 63% cover:

@isTest
private class AssessmentcontrollerTest
{
        public static testmethod void AssessmentcontrollerTest()
        {
            Boolean isittrue = true;
            final Boolean istrue = True;
           
            PageReference pageRef =Page.AX; // used to set a page           
            test.setCurrentPage(pageRef);  // set starting page
            ApexPages.CurrentPage().getParameters().put('cid', '003R000000Y7Gw4');
            ApexPages.CurrentPage().getParameters().put('cc', 'True');
           
           
            // instanciate and construct the controller class
            Assessmentcontroller AC = new Assessmentcontroller();
                
                // Instantiate a new controller with all parameters in the page
   
        System.debug('Inserting contact detail(single record validation)');
       
        Contact testrec = new Contact(Is_Client__c = True, LastName = 'notlob', Client_Address_1__c = '1 The Rd',
        Client_County__c = 'somecounty', ContactType__c = 'Client', Client_Town__c = 'Bolton', Client_Postcode__c = 'postcode1',
        Client_DOB__c = System.today());
        insert testrec;
       
        //Validate single insert
   
        for(Contact c:[SELECT Is_Client__c,LastName, Client_Address_1__c,Client_County__c, ContactType__c, Client_Town__c, Client_Postcode__c,
        Client_DOB__c  FROM Contact
            WHERE CreatedDate = TODAY
            and Is_Client__c != null]) {
                isittrue = c.Is_Client__c;
            }
       
        System.assertEquals(isittrue, True);

           }    
         
}

****** Controller *******

public class Assessmentcontroller {

    public String conid { get; private set; }   
    public String notclient { get; private set; }   
    public boolean Notcid { get; private set; }   
    public boolean Nocid { get; private set; }   
    public boolean Gotcid { get; private set; }
     
    public Assessmentcontroller(){
    if(ApexPages.currentPage().getParameters().get('cid')!= null){     
        conid = '?cid='+ApexPages.currentPage().getParameters().get('cid'); //assign client record number to conid
        notclient = ApexPages.currentPage().getParameters().get('cc');
            if (notclient == 'false'){
                Notcid = True;
            }
        Nocid = False;
        Gotcid = True;
        }else{
        Nocid = True;
        Gotcid = False;
        }
    }

    public String Id  { get; private set; }
   
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                Id id = ApexPages.currentPage().getParameters().get('cid');
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(               
                      [select name, Is_Client__c,Client_DOB__c, Contact_Ref__c, DNR_Authorisation_Uploaded__c from Contact where Id = :id]));
            }
            return setCon;
        }
        set;
    }
    // Initialize setCon and return a list of records     
    public List<Contact> getContacts() {
         return (List<Contact>) setCon.getRecords();
    }
}

Thanks Steve

Hi all, the code below allows me to find the last record greated on the MSQoL__c object and display the name field.

I have a number of different objects that could need to be displayed with this. Now 9 nested if statements could do the job but it wouldn't be pretty. I am carrying the object name in the url from the page no problem but can't get a variable to work within the select statement or in the 'for loop' as the custom object, nor in the list< >. It is found by a for loop but can't use it.

Is there a way to achieve this? all ideas gratefully excepted.

 

 public ApexPages.StandardSetController setrec {
        get {          
            if(setrec == null){    
                setrec = new ApexPages.StandardSetController(Database.getQueryLocator(
                  [SELECT name
                    From MSQoL__c
                    Where MSQClient__c = :ApexPages.currentPage().getParameters().get('cid') Order By name DESC limit 1]));       
            }
            for(Integer i=0; i<mystrings.size(); i++){
                if (ApexPages.currentPage().getParameters().get('form') == mystrings[i]){
                    System.debug(i);
                    MSQoL__c a = [SELECT name From MSQoL__c Where MSQClient__c = :ApexPages.currentPage().getParameters().get('cid') Order By name DESC limit 1];
                    pn.RelformRec__c = a.name;
                }
            }
            return setrec;      
        }
        set;
    }

    // Initialize setrec and return a list of records read by the rec call and the field name you want to see..
  
    public List<MSQoL__c> getSISs() {
         return (List<MSQoL__c>) setrec.getRecords();
    }

Hi

    Trying to use an array to give a field a value based on the url element 'form' which i have used from a previous page.

I cant seem to get the right format for the for loop, ths code below throws up, Compile Error: Loop must iterate over a collection type: Integer. Am a bit lost as to what to do. Please help if you can, thanks.

 

   String[] mystrings = new String[]{'SIS__c', 'MSQ__c', 'PDQ_39__c'};
    String[] mystring2 = new String[]{'StrImp', 'MSquiz', 'PDQ'};
    public void PNExtMethod(){
        for(Integer i : mystrings.size()){
            if (ApexPages.currentPage().getParameters().get('form') == mystrings[i]){
                System.debug(i);
                pn.Relobject__c = mystring2[i];
            }
        }
    }*

Hi all, I need to redirect from a customvf page to another when the save action has occurred. It is a custom object and the normal save is working fine but i need this redirect. I found this example on the boards which has been marked as the solution but when i try to use it it tells me :

System.NullPointerException: Attempt to de-reference a null object
Class.SISEdit.saveandnotes: line 50, column 1 

 Anyone got any ideas whats up?

 

     public PageReference saveandnotes() {
          controller.save(); // This takes care of the details for you.
          PageReference ProgressNotes = Page.PN;
          ProgressNotes.setRedirect(true);
        return ProgressNotes;
    } 

Hi, if you open a standard page there is a related list called notes & attachments.

I want to show it on a visualforce page and cannot find out how anywhere in the documentation. 

I am a very new developer learning as I go. Could someone please help.

Sorry it is probably very easy but so much documentation and over 2hrs searching with no results!!

 

Thanks

 

Steve

I am trying to write my first controller class and am finding the concept tricky. I want a controller to show a list contacts from the contact standard object and filter what is shown by a boolean check form a check box. I think I have it with:

public with sharing class Assessmentcontroller {

    Public List<cContact> clientList {get; set;}

    Public List<cContact> getContacts(){
        if(clientList == null){
            clientList = new List<cContact>();
             for(Contact c : [Select name, Client_DOB__c, Contact_Ref__c From Contact where Is_client__c = True])
                clientList.add(new cContact(c));
        }
        return clientList;
    }
    public pageReference clientList(){
        List<Contact> clientList = new List<Contact>();
        for(cContact cCon : getContacts()){
            clientList.add(cCon.con);
        }
   
    system.debug('These are the clients...');
    for(Contact con : clientList){
        system.debug(con);
    }
    return null;
    }
   
    public class cContact{
        public Contact con {get; set;}
   
        public cContact(Contact c){
            con = c;
        }
    }
   
   
}

Then trying to write the test methods to cover it .

ps. is there anyone in north machester who could give me some time to cover some basics?

Thanks

When you drag the standard field into a standard layout of the contact object it displays the name of the user who created the record and the date & time of creation.

 

When I used it in a vf page all it shows is 005200000025bX9AAI?

 

Tried <apex:outputlabel value="{!contact.CreatedBy}"/>, <apex:outputText >{!contact.CreatedBy}</apex:outputText> as two ways to display it with the same results.

 

Any idea's whats wrong and how I get it to do the  same as it would in a normal layout.

 

Thanks

I need to set a number as part of an id number on a form to equal the current year after 01/04 and equal to current year - 1 before. I then want to set that number as the default value in a number field.

Being very new to this its not coming easily and I am on a bit of a deadline so any help would speed things up!

thanks

 

I have a table on a visualforce page embedded in a standard view and I want to change the colour of its background dependent on the check box which is on the standard page.
I basically need to have a view open which when a check box is ticked a square turns red.
The only way i could think of doing it was as above but i cannot get the value of a custom field (the check box) to be read on the visualforce page. I can display a standard field values onto the page no problem with <apex:outputField value="{!Contact.name}"/> but not the custom fields.
If you have an easier way to achieve this effect please let me know or how to get the boolean value onto my page that will do just as well.

Thank you

Steve

A very new developer.

 



Hi all, I have been developing a site in the sandbox which has unit testing code with between 70 - 92% code coverage with a calculated 78% average. I know this isn't a great job well done but it meets minimum requirements for now.

But then when I migrate it to the production environment, the live site, the validation check says it will fail to install with 0% code coverage. How can that be?

Why would it say that?

Do all classes have to exceed the 75% individually?

If any system.assert tests fail, would that cause my problem?

Has anyone got anything that will help me?

I have not got a clue as to why this is the case. Please some advice would be a god send!

 

Thanks in advance,

 

Steve

PageReference p = new PageReference('/00OM0000000SNVS+?pv0=’+ stringUrl);

 

the error says "line breaks not allowed in string literals at line 17 column -1"

 

Can anyone pls help to fix thsi error

 

Thanks

Hi all, needed to have a page redirect on save and achieved it with

 

public PageReference saveandnotes() {
          stdCtrl.save(); // This takes care of the details for you.
          PageReference pn = Page.PN;
          pn.getParameters().put('cid',ApexPages.currentPage().getParameters().get('cid'));
          pn.getParameters().put('form','OTReview__c');
          pn.setRedirect(true);
       return pn;
    }  

Trying now to write the unit test for it and getting no were fast. Got 70% cover overal just need this I think. So far i tried this but get the error

Compile Error: Method does not exist or incorrect signature: controller.saveandnotes() with 

Public Static TestMethod void saveandnotes()
        {
            // this builds the constructor for the controller which links this to the correct object
            OTReview__c testrev = new OTReview__c(OTLims1__c = 'abc', OTDiag__c = 'notlob', OTCognition__c = 'wife & kids',
                OTMental__c = 'can talk', OTPhysical__c = 'make tea', OTSensation__c = '50mg', OTMed__c = 'asprin',
                OTSafe__c = 'Yes');
                Insert testrev;

            ApexPages.StandardController stdController = new ApexPages.StandardController(testrev);
            OTRevConedit ARed = new OTRevConedit(stdcontroller);
           
            ApexPages.CurrentPage().getParameters().put('cid', '003R000000Y7Gw4');
            ApexPages.CurrentPage().getParameters().put('form', 'OTReview__c');
            String nextPage = controller.saveandnotes().getUrl();

            system.assertEquals('/apex/PN?cid=003R000000Y7Gw4', nextPage);

        }

  Any help would by appreciated emmensely.

Thanks

 

Steve

HI, New to this so treat me as dumb. Writing a unit test class for a very small class but keep getting this message

Error: Compile Error: Constructor not defined: [attachmentsample].<Constructor>()  yet I used the same format in another test and it doesn't complain! what is missing? cant see the wood for the tree's i think.

** class **

public class attachmentsample {

    public attachmentsample(ApexPages.StandardController controller) {

    }
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
  
    Public Pagereference Savedoc()
    {
        String accid = System.currentPagereference().getParameters().get('id');

        Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
        
         /* insert the attachment */
         insert a;
        return NULL;
    }  

}

** controller **

public class attachmentsampleTest {

    public static void attachmentsampleTest(ApexPages.StandardController controller) {
        PageReference pageRef = Page.attachment;
        test.setCurrentPage(pageRef);
        ApexPages.CurrentPage().getParameters().put('id', '003R000000Y7Gw4');

        attachmentsample atsam = new attachmentsample();
       
        controller.myfile.name = 'testdoc';
        controller.myfile.body = 'testing 123';
      
    }
}

Please I am really under pressure to get this stuff working but keep going round in circles.

Thanks

Steve.

 

 

Hi all, development in the sandbox doesn't need the testing so been busy developing. The assessment controller is stand alone with no object just a page with direction and display controls. I know I am a pain but could someone help please? with comments please as I am very new. ?

Here's my code so far giving me 63% cover:

@isTest
private class AssessmentcontrollerTest
{
        public static testmethod void AssessmentcontrollerTest()
        {
            Boolean isittrue = true;
            final Boolean istrue = True;
           
            PageReference pageRef =Page.AX; // used to set a page           
            test.setCurrentPage(pageRef);  // set starting page
            ApexPages.CurrentPage().getParameters().put('cid', '003R000000Y7Gw4');
            ApexPages.CurrentPage().getParameters().put('cc', 'True');
           
           
            // instanciate and construct the controller class
            Assessmentcontroller AC = new Assessmentcontroller();
                
                // Instantiate a new controller with all parameters in the page
   
        System.debug('Inserting contact detail(single record validation)');
       
        Contact testrec = new Contact(Is_Client__c = True, LastName = 'notlob', Client_Address_1__c = '1 The Rd',
        Client_County__c = 'somecounty', ContactType__c = 'Client', Client_Town__c = 'Bolton', Client_Postcode__c = 'postcode1',
        Client_DOB__c = System.today());
        insert testrec;
       
        //Validate single insert
   
        for(Contact c:[SELECT Is_Client__c,LastName, Client_Address_1__c,Client_County__c, ContactType__c, Client_Town__c, Client_Postcode__c,
        Client_DOB__c  FROM Contact
            WHERE CreatedDate = TODAY
            and Is_Client__c != null]) {
                isittrue = c.Is_Client__c;
            }
       
        System.assertEquals(isittrue, True);

           }    
         
}

****** Controller *******

public class Assessmentcontroller {

    public String conid { get; private set; }   
    public String notclient { get; private set; }   
    public boolean Notcid { get; private set; }   
    public boolean Nocid { get; private set; }   
    public boolean Gotcid { get; private set; }
     
    public Assessmentcontroller(){
    if(ApexPages.currentPage().getParameters().get('cid')!= null){     
        conid = '?cid='+ApexPages.currentPage().getParameters().get('cid'); //assign client record number to conid
        notclient = ApexPages.currentPage().getParameters().get('cc');
            if (notclient == 'false'){
                Notcid = True;
            }
        Nocid = False;
        Gotcid = True;
        }else{
        Nocid = True;
        Gotcid = False;
        }
    }

    public String Id  { get; private set; }
   
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                Id id = ApexPages.currentPage().getParameters().get('cid');
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(               
                      [select name, Is_Client__c,Client_DOB__c, Contact_Ref__c, DNR_Authorisation_Uploaded__c from Contact where Id = :id]));
            }
            return setCon;
        }
        set;
    }
    // Initialize setCon and return a list of records     
    public List<Contact> getContacts() {
         return (List<Contact>) setCon.getRecords();
    }
}

Thanks Steve

Hi all, the code below allows me to find the last record greated on the MSQoL__c object and display the name field.

I have a number of different objects that could need to be displayed with this. Now 9 nested if statements could do the job but it wouldn't be pretty. I am carrying the object name in the url from the page no problem but can't get a variable to work within the select statement or in the 'for loop' as the custom object, nor in the list< >. It is found by a for loop but can't use it.

Is there a way to achieve this? all ideas gratefully excepted.

 

 public ApexPages.StandardSetController setrec {
        get {          
            if(setrec == null){    
                setrec = new ApexPages.StandardSetController(Database.getQueryLocator(
                  [SELECT name
                    From MSQoL__c
                    Where MSQClient__c = :ApexPages.currentPage().getParameters().get('cid') Order By name DESC limit 1]));       
            }
            for(Integer i=0; i<mystrings.size(); i++){
                if (ApexPages.currentPage().getParameters().get('form') == mystrings[i]){
                    System.debug(i);
                    MSQoL__c a = [SELECT name From MSQoL__c Where MSQClient__c = :ApexPages.currentPage().getParameters().get('cid') Order By name DESC limit 1];
                    pn.RelformRec__c = a.name;
                }
            }
            return setrec;      
        }
        set;
    }

    // Initialize setrec and return a list of records read by the rec call and the field name you want to see..
  
    public List<MSQoL__c> getSISs() {
         return (List<MSQoL__c>) setrec.getRecords();
    }

Hi

    Trying to use an array to give a field a value based on the url element 'form' which i have used from a previous page.

I cant seem to get the right format for the for loop, ths code below throws up, Compile Error: Loop must iterate over a collection type: Integer. Am a bit lost as to what to do. Please help if you can, thanks.

 

   String[] mystrings = new String[]{'SIS__c', 'MSQ__c', 'PDQ_39__c'};
    String[] mystring2 = new String[]{'StrImp', 'MSquiz', 'PDQ'};
    public void PNExtMethod(){
        for(Integer i : mystrings.size()){
            if (ApexPages.currentPage().getParameters().get('form') == mystrings[i]){
                System.debug(i);
                pn.Relobject__c = mystring2[i];
            }
        }
    }*

Hi all, I need to redirect from a customvf page to another when the save action has occurred. It is a custom object and the normal save is working fine but i need this redirect. I found this example on the boards which has been marked as the solution but when i try to use it it tells me :

System.NullPointerException: Attempt to de-reference a null object
Class.SISEdit.saveandnotes: line 50, column 1 

 Anyone got any ideas whats up?

 

     public PageReference saveandnotes() {
          controller.save(); // This takes care of the details for you.
          PageReference ProgressNotes = Page.PN;
          ProgressNotes.setRedirect(true);
        return ProgressNotes;
    } 

Hi, if you open a standard page there is a related list called notes & attachments.

I want to show it on a visualforce page and cannot find out how anywhere in the documentation. 

I am a very new developer learning as I go. Could someone please help.

Sorry it is probably very easy but so much documentation and over 2hrs searching with no results!!

 

Thanks

 

Steve

I am trying to write my first controller class and am finding the concept tricky. I want a controller to show a list contacts from the contact standard object and filter what is shown by a boolean check form a check box. I think I have it with:

public with sharing class Assessmentcontroller {

    Public List<cContact> clientList {get; set;}

    Public List<cContact> getContacts(){
        if(clientList == null){
            clientList = new List<cContact>();
             for(Contact c : [Select name, Client_DOB__c, Contact_Ref__c From Contact where Is_client__c = True])
                clientList.add(new cContact(c));
        }
        return clientList;
    }
    public pageReference clientList(){
        List<Contact> clientList = new List<Contact>();
        for(cContact cCon : getContacts()){
            clientList.add(cCon.con);
        }
   
    system.debug('These are the clients...');
    for(Contact con : clientList){
        system.debug(con);
    }
    return null;
    }
   
    public class cContact{
        public Contact con {get; set;}
   
        public cContact(Contact c){
            con = c;
        }
    }
   
   
}

Then trying to write the test methods to cover it .

ps. is there anyone in north machester who could give me some time to cover some basics?

Thanks

I am attempting to pull the state__c value from the site__c object where the site__c.id matches the selected value from a selectList.  I have tried 2 different ways and am unable to avoid errors. 

 

-----------------

Attempt #1

    public String siteState
    {
        get {return [SELECT state__c FROM site__c WHERE id = :site LIMIT 1]; }
        set;
    }

 

The error I receive is:

Error: Compile Error: Return value must be of type: String at line 17 column 14

-----------------

Attempt #2

    public String siteState
    {
        get
        {
            String tmpState = [SELECT state__c FROM site__c WHERE id = :site LIMIT 1];
            return tmpState;
        }
        set;
    }

 

The error I receive is:

Error: Compile Error: Illegal assignment from LIST:SOBJECT:Site__c to String at line 19 column 13

-----------------

 

Any help is greatly appreciated.