• gwp
  • NEWBIE
  • 55 Points
  • Member since 2009

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies

I have looked in the Cookbook, Apex and VisualForce guides, and I've also searched these forums for a solution, but haven't found anything as of yet.

 

Could someone please point me in the best direction for accomplishing the following:

 

 

I have created a VisualForce page that references a custom object (called Invoice) which is in a master detail relationship with a child object (Inventory).  I've added a custom link to the Invoice page layout which correctly renders information stored from the Invoice record and any children Inventory objects.  We print the Invoice for our customer from this page, or email them an invoice from a modified VisualForce template.

 

Is it possible to modify the VisualForce page or the custom link I'm calling to render the page to display multiple instances of this page in one file or one browser window?  For example, if I'm trying to print 50 invoices related to another custom object, Store, with a lookup relationship, is there an easier way to print all fifty of these invoices than clicking the VisualForce link on each individual record?  If this is easier to do in a PDF than rendering in the browser, that would be acceptable as well.

 

Thanks for your time and attention, and let me know if I need to be more descriptive.

I need to create a document (ie a nice looking deep report) that contains all the records from a custom object including each record's related lists. I've tried using the new reports to get the data but they are limited to three objects, and I can't get CongaMerge to do it because their SOQL (Conga Query) doesn't support sub selects.

 

One person suggested to send a visualforce page a list of Id's in the URL (or have the controller look up a list of sobjects) and use the apex:repeat and apex:detail tags to render the records as this would use the object's page layout and include the related lists, voila!

 

But I'm falling over at the first hurdle: I just can't get the page to render multiple records.

 

Attempt 1 (Url is /apex/mapPage?id=XXXXXXXXXX,XXXXXXXXX,XXXXXXXX) The result is the detail tag complaining that it can't accept "XXXXXXXXXX,XXXXXXXXX..." as an ID, so clearly I've not wired up the repeat variable and detail tags correctly.

 

<!-- Page -->
<apex:page controller="DominoController" id="thePage">
    <apex:repeat var="string" value="{!strings}" id="theRepeat">
        <apex:detail />
        <hr/>
    </apex:repeat>
</apex:page>

/* Controller */
public with sharing class DominoController {
    public String[] idS{ get; set; }
    public DominoController() {
        String[]    idS = ApexPages.currentPage().getParameters().get('id').split(',');
        /* This successfully gets me a string array of id's */
    }
}

 

 

Attempt 2 (Id's are looked up using a select statement in the controller and put into "oList" but I can't get the detail tag to take the list items, I just get the same nothing repeated X number of times - note the rerender attribute is just a desparate attempt)

 

<!-- Page -->
<apex:page controller="DominoController" id="thePage">
    <apex:repeat var="o" value="{!oList}" id="theRepeat">
        <apex:detail rerender="{!o}"/>
        <hr/>Line break<hr/>
    </apex:repeat>
</apex:page>

/* Controller */
public with sharing class DominoController {
    public List<sObject> oList{ get; set; }    
    public DominoController() {
        soqlQuery = 'select id, Name from MyCustomObject';
        oList= Database.query(soqlQuery);
        /* This successfully gets me a list of objects */
    }
}

 

Heeeeeelp!

 

 

  • April 27, 2011
  • Like
  • 0

Hi,

 

I created several sites and pages and now I no longer need them. How can I delete them? The page is dependant on the site, but when I open the sites to delete them I can only deactivate, and not remove them.

 

Thanks

 

Matt

  • April 12, 2010
  • Like
  • 0

Hi,

 

I'm writing an "update Account" function for my partner portal users who don't have the rights to edit an account directly. This function creates a new lead, populated by the source account and it's main contact.

 

I want to write some Apex that will look up the conversion field mappings used in the conversion process and use these as a reference to tell my Apex script how to to populate my new Lead so that as fields are added and mappings changed over time I will not have to re-write the apex code.

 

Example:

Consider a lead L is converted into account A and contact C. My portal user then clicks on a button and some Apex creates lead L2 populating it with account B and contact C's information:

 

Lead L: Name= Bob Brady, Company = United Nations, Custom_field_IsNGO__c = True

 

***converts to...***

Account A: Name = A.Company, Custom_field_IsImportantClient = A.Custom_field_IsNGO__c

Contact C: Name = Bob Brady

 

***user clicks on update button and a new lead is created...***

Lead L2: Name = C.Name, Company = B.Name, CustomField_IsNGO__c = B.Custom_field_IsImportantClient

 

To solve this last step I beleive I need to either:

 

- hard code the field mappings (BAD! My org has no techies if I am not there, plus this is a major pain when customizing the conversion process for a DBA as it is effectively hidden logic)

 

or - create a custom object to act as a mapper (better but still "bad" as this means maintaining the salesforce lead conversion mapping logic in two places)

 

or - look up the standard salesforce conversion mapping and using that as a reference to transfer the data into the new lead L2

 

Any suggestions or ways anyone has worked out to do this kind of look up in Apex? The describe info only gets the standard schema data... And I don't see any schema object containing the data I need...

 

Thanks!

 

Matt

  • April 12, 2010
  • Like
  • 0

HI, I just cant seem to get any coverage on my trigger that is run when a custom object gets update.

A visual force page uses the following code to update a lead via a trigger attached to a custom object that the page creates.

 

I have one class and one trigger, I have put the test method in the class. This feels like the right thing to do but for the life of me (it's my first script) I cant get the test to run. The code is basic and does work in sandbox...

 

 

public with sharing class ManagePartnerLeadClass { public final Lead l; Lead_Feedback__c lf; public string comment {get; set;} private ApexPages.StandardController lController; public ManagePartnerLeadClass(ApexPages.StandardController controller) { lController = controller; this.l = (Lead)controller.getRecord(); } public PageReference CreateLeadApproval() { try { lf = new Lead_Feedback__c(); lf.LeadID__c = l.ID; lf.Lead_Approval_Status__c = 'Approved'; lf.Comments__c = comment; insert lf; } catch(DmlException ex) { ApexPages.addMessages(ex); } return new PageReference('http://www.salesforcewebform.com/thankyou.html'); } static testMethod void myUnitTest() { //Create Lead for the test Lead l = new Lead( Email='test@gwp.test', LastName='Test', Company='Test' ); insert l; // add a known lead //New instance of the standard page controller for this lead ApexPages.StandardController con = new ApexPages.StandardController(l); //New instance of the extension class ManagePartnerLeadClass mpl = new ManagePartnerLeadClass(con); //Set loose values mpl.comment = 'test comment'; //Test methods PageReference endPage = mpl.CreateLeadApproval(); //Confirm output System.assertEquals(endPage.getUrl(),'http://www.salesforcewebform.com/thankyou.html'); //Test feedback insert Lead_Feedback__c tlf = new Lead_Feedback__c(LeadID__c = l.ID, Lead_Approval_Status__c = 'Approved',Comments__c='Trigger test'); insert tlf; //Test to see if trigger was hit String leadId = tlf.LeadID__c; Lead trl = [select Id from Lead where Id =:leadId]; System.assertEquals(leadId, trl.Id); } }

 The trigger

 

trigger Update_Lead_Feedback on Lead_Feedback__c (after insert) { //also , after update required? // trigger automatically syncs Lead Approval to the Lead record. Lead l; for (Lead_Feedback__c lf : Trigger.new) { String leadId = lf.LeadID__c; if (leadId !=null && leadId !='') { l = [select Id from Lead where Id=:leadId]; l.Lead_Approval__c = lf.Lead_Approval_Status__c; l.Lead_Approval_Feedback__c = lf.Comments__c; update l; } } }

 

 

 

 Big thanks, I'm sitting on a risky project after having toted Salesforce as THE platform we should be using... now I'm beginning to worry as development is down to a snails pace, any suggestions to improve the code? Perhaps it's my whole approach???

 

 

  • December 06, 2009
  • Like
  • 0

Hi, I developed the below code with the help from a sales engineer. This is my first peice of development for salesfroce so sorry if this is obvious but I've spent quite a while trying to understand the unit test concept in development.

 

It's a simple class that updates a custom object Lead_Feedback__c when a Visual Force web form submits it's result (it triggers one of three methods to do a simple update).

 

The main script ha been tested in the Sales Engineers environemtn, but when trying to move it over to our production enironment we are having trouble and the engineer doesn't know how to manage unit tests (an neither do I).

 

If you oculd help me wiht this I'm sure I can use the same approach for a trigger and VF page we've created as part of the solution:

 

 

/* Manage Partner Lead APEX Class */ public with sharing class ManagePartnerLeadClass { public final Lead l; Lead_Feedback__c lf; public string comment {get; set;} private ApexPages.StandardController lController; public ManagePartnerLeadClass(ApexPages.StandardController controller) { lController = controller; this.l = (Lead)controller.getRecord(); } //Instead of using the hard copy text you should be able to look up the value of the button selected by the user //But for the proof of concept this is fine public PageReference CreateLeadNeedMoreInfo() { try { lf = new Lead_Feedback__c(); lf.LeadID__c = l.ID; lf.Lead_Approval_Status__c = 'Need More Info'; lf.Comments__c = comment; insert lf; } catch(DmlException ex) { ApexPages.addMessages(ex); } return new PageReference('http://www.salesforcewebform.com/thankyou.html'); } public PageReference CreateLeadApproval() { try { lf = new Lead_Feedback__c(); lf.LeadID__c = l.ID; lf.Lead_Approval_Status__c = 'Approved'; lf.Comments__c = comment; insert lf; } catch(DmlException ex) { ApexPages.addMessages(ex); } return new PageReference('http://www.salesforcewebform.com/thankyou.html'); } public PageReference CreateLeadRejection() { try { lf = new Lead_Feedback__c(); lf.LeadID__c = l.ID; lf.Lead_Approval_Status__c = 'Rejected'; lf.Comments__c = comment; insert lf; } catch(DmlException ex) { ApexPages.addMessages(ex); } return new PageReference('http://www.salesforcewebform.com/thankyou.html'); } // Test method to bring this class's test coverage over the required 75% static testMethod void testLeadFeedback() { //Set context //Positive tests String comment = 'test comment'; Lead l = new Lead( Email='test@gwp.org', LastName='lead test', Company='lead test' ); insert l;// add a known lead //Negative tests CreateLeadApproval(); CreateLeadRejection(); CreateLeadNeedMoreInfo(); } }

 The tests above are obviously incomplete, but I can't get my head around the context here so I can't even get this to be accepted, syntax issues and all. I'm sure it's obvious to someone who's more experienced...Any suggestions on how I can complete it? The main body works as a proof of concept, it's just the tests...

 

Thanks!

 

 

 

 

  • December 04, 2009
  • Like
  • 0

I need to create a document (ie a nice looking deep report) that contains all the records from a custom object including each record's related lists. I've tried using the new reports to get the data but they are limited to three objects, and I can't get CongaMerge to do it because their SOQL (Conga Query) doesn't support sub selects.

 

One person suggested to send a visualforce page a list of Id's in the URL (or have the controller look up a list of sobjects) and use the apex:repeat and apex:detail tags to render the records as this would use the object's page layout and include the related lists, voila!

 

But I'm falling over at the first hurdle: I just can't get the page to render multiple records.

 

Attempt 1 (Url is /apex/mapPage?id=XXXXXXXXXX,XXXXXXXXX,XXXXXXXX) The result is the detail tag complaining that it can't accept "XXXXXXXXXX,XXXXXXXXX..." as an ID, so clearly I've not wired up the repeat variable and detail tags correctly.

 

<!-- Page -->
<apex:page controller="DominoController" id="thePage">
    <apex:repeat var="string" value="{!strings}" id="theRepeat">
        <apex:detail />
        <hr/>
    </apex:repeat>
</apex:page>

/* Controller */
public with sharing class DominoController {
    public String[] idS{ get; set; }
    public DominoController() {
        String[]    idS = ApexPages.currentPage().getParameters().get('id').split(',');
        /* This successfully gets me a string array of id's */
    }
}

 

 

Attempt 2 (Id's are looked up using a select statement in the controller and put into "oList" but I can't get the detail tag to take the list items, I just get the same nothing repeated X number of times - note the rerender attribute is just a desparate attempt)

 

<!-- Page -->
<apex:page controller="DominoController" id="thePage">
    <apex:repeat var="o" value="{!oList}" id="theRepeat">
        <apex:detail rerender="{!o}"/>
        <hr/>Line break<hr/>
    </apex:repeat>
</apex:page>

/* Controller */
public with sharing class DominoController {
    public List<sObject> oList{ get; set; }    
    public DominoController() {
        soqlQuery = 'select id, Name from MyCustomObject';
        oList= Database.query(soqlQuery);
        /* This successfully gets me a list of objects */
    }
}

 

Heeeeeelp!

 

 

  • April 27, 2011
  • Like
  • 0

We are receiving an error while deploying to production:
MyProfilePageController.testSave System.QueryException: List has no rows for assignment to SObject
Class.MyProfilePageController.testSave: line 78, column 35

MyProfilePageController class is automatically generated, I mean we didn't write code for this.

 

 

/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
public class MyProfilePageController {

    private User user;
    private boolean isEdit = false;
    
    public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
        // guest users should never be able to access this page
        if (user.usertype == 'GUEST') {
            throw new NoAccessException();
        }
    }
    
    public Boolean getIsEdit() {
        return isEdit;
    }
    
    public void edit() {
        isEdit=true;
    }    
    
    public void save() {
        if (user.contact != null) {              
            setContactFields(user.contact);
        }
        
        try {
            update user;
            if (user.contact != null) { 
                update user.contact;
            }
            isEdit=false;
        } catch(DmlException e) {
            ApexPages.addMessages(e);
        }
    }
    
    public PageReference changePassword() {
        return Page.ChangePassword;
    }
    
    public void cancel() {
        isEdit=false;
        user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
    }
    
    private void setContactFields(Contact c) {
        c.title = user.title;
        c.firstname = user.firstname;
        c.lastname = user.lastname;
        c.email = user.email;
        c.phone = user.phone;
        c.mobilephone = user.mobilephone;
        c.fax = user.fax;
        c.mailingstreet = user.street;
        c.mailingcity = user.city;
        c.mailingstate = user.state;
        c.mailingpostalcode = user.postalcode;
        c.mailingcountry = user.country;
    }

    static testMethod void testSave() {         
        // Modify the test to query for a portal user that exists in your org
        User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];
        System.assert(existingPortalUser != null, 'This test depends on an existing test portal user to run');
        
        String randFax = Math.rint(Math.random() * 1000) + '5551234';
        
        System.runAs(existingPortalUser) {
            MyProfilePageController controller = new MyProfilePageController();
            System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
            System.assert(controller.isEdit == false, 'isEdit should default to false');
            controller.edit();
            System.assert(controller.isEdit == true);
            
            controller.cancel();
            System.assert(controller.isEdit == false);
            
            controller.getUser().Fax = randFax;
            controller.save();
            System.assert(controller.isEdit == false);
        }
        
        // verify that the user and contact were updated
        existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id];
        System.assert(existingPortalUser.fax == randFax);
        //System.assert(existingPortalUser.Contact.fax == randFax);
    }
}

 

 

The line highlighted in red is the error line.

 

Please help me.

 

With Winter '11, if you create a Site, a new Salesforce-provided class gets deployed to your org: MyProfilePageController.cls

 

There is test code in this class that fails if you don't have a portal user installed. This prevents you from doing anything in that org that requires running all tests.

 

Here is the error:

 

System.QueryException: List has no rows for assignment to SObject

Class.MyProfilePageController.testSave: line 78, column 35 External entry point

 

and the line in question:

 

 

User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];

 

This failure prevents doing any save from Eclipse. You can't deploy new code, edit object metadata files, etc. Complete showstopper.

 

Can anyone:

 * confirm this (we think reproducing will require that you create a new Site, perhaps the first Site in the org, after Winter 11)

 * think of a work-around (tried enabling self-service portal, but it doesn't create the required user type)

 

Anyone from Salesforce confirm that this is a bug and not something we're doing wrong?

 

Thanks!

 

Here is the entire class:

 

/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
public class MyProfilePageController {

    private User user;
    private boolean isEdit = false;
    
    public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
        // guest users should never be able to access this page
        if (user.usertype == 'GUEST') {
            throw new NoAccessException();
        }
    }
    
    public Boolean getIsEdit() {
        return isEdit;
    }
    
    public void edit() {
        isEdit=true;
    }    
    
    public void save() {
        if (user.contact != null) {              
            setContactFields(user.contact);
        }
        
        try {
            update user;
            if (user.contact != null) { 
                update user.contact;
            }
            isEdit=false;
        } catch(DmlException e) {
            ApexPages.addMessages(e);
        }
    }
    
    public PageReference changePassword() {
        return Page.ChangePassword;
    }
    
    public void cancel() {
        isEdit=false;
        user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
    }
    
    private void setContactFields(Contact c) {
        c.title = user.title;
        c.firstname = user.firstname;
        c.lastname = user.lastname;
        c.email = user.email;
        c.phone = user.phone;
        c.mobilephone = user.mobilephone;
        c.fax = user.fax;
        c.mailingstreet = user.street;
        c.mailingcity = user.city;
        c.mailingstate = user.state;
        c.mailingpostalcode = user.postalcode;
        c.mailingcountry = user.country;
    }

    static testMethod void testSave() {         
        // Modify the test to query for a portal user that exists in your org
        User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];
        System.assert(existingPortalUser != null, 'This test depends on an existing test portal user to run');
        
        String randFax = Math.rint(Math.random() * 1000) + '5551234';
        
        System.runAs(existingPortalUser) {
            MyProfilePageController controller = new MyProfilePageController();
            System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
            System.assert(controller.isEdit == false, 'isEdit should default to false');
            controller.edit();
            System.assert(controller.isEdit == true);
            
            controller.cancel();
            System.assert(controller.isEdit == false);
            
            controller.getUser().Fax = randFax;
            controller.save();
            System.assert(controller.isEdit == false);
        }
        
        // verify that the user and contact were updated
        existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id];
        System.assert(existingPortalUser.fax == randFax);
        System.assert(existingPortalUser.Contact.fax == randFax);
    }

}

 

 

 

  • October 15, 2010
  • Like
  • 0

I have looked in the Cookbook, Apex and VisualForce guides, and I've also searched these forums for a solution, but haven't found anything as of yet.

 

Could someone please point me in the best direction for accomplishing the following:

 

 

I have created a VisualForce page that references a custom object (called Invoice) which is in a master detail relationship with a child object (Inventory).  I've added a custom link to the Invoice page layout which correctly renders information stored from the Invoice record and any children Inventory objects.  We print the Invoice for our customer from this page, or email them an invoice from a modified VisualForce template.

 

Is it possible to modify the VisualForce page or the custom link I'm calling to render the page to display multiple instances of this page in one file or one browser window?  For example, if I'm trying to print 50 invoices related to another custom object, Store, with a lookup relationship, is there an easier way to print all fifty of these invoices than clicking the VisualForce link on each individual record?  If this is easier to do in a PDF than rendering in the browser, that would be acceptable as well.

 

Thanks for your time and attention, and let me know if I need to be more descriptive.

Hi, I can't get Salesforce to import dates.  I did my trial import and 5 out of 6 date of births failed.  I have changed the excel formular to be the same as the help and training format of:

m/d/yyyy h:mm AM/PM

but still have issues.

Any help would be VERY appreciated!

Thnaks!

"Send an Email" through the salesforce UI allows you to specify a "Related To" record which can be of type custom object OR standard object.

However the WhatId property through the API only allows standard objects.  Is this expected?

-------------- from the apex language reference -------------------------
Optional. If you specify a contact for the targetObjectId field, you can specify a whatId as well. This helps to further ensure that merge fields in the template contain the correct data. The value must be one of the following types:
  • Account
  • Asset
  • Campaign
  • Case
  • Contract
  • Opportunity
  • Order
  • Product
  • Solution
  • Custom



  • September 16, 2008
  • Like
  • 0