• S_Lie
  • NEWBIE
  • 50 Points
  • Member since 2009

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 38
    Replies

I have a VF Page where the constructor access a get method which queries a list of Accounts for display in a PageBlockTable.

 

If the list gets loaded, the page displays correctly with the table of Accounts.

 

However, if no Accounts are loaded from the query, the page is blank. What I want to do is redirect to a different page with a message saying No Accounts are available with a button to return back to another page. 

 

I haven't been able to figure how to add this redirect though. 

 

I have a PageReference method which is set correctly, and the constructor reads

 

 

public class AccountList { public AccountList() { EligibleAccts = getEligibleAccts(); if (getEligibleAccts().isEmpty()) { NoEligibleAccts(); } system.debug('EligibleAccts size is '+EligibleAccts.size()); }

 

public Account[] getEligibleAccts()

{

  EligibleAccts = [QUERY];
return EligibleAccts;

} public Pagereference NoEligibleAccts() { PageReference PR = new PageReference('/apex/NoEligibleAccts'); PR.setRedirect(true); }

 

 THE PAGE CODE

 

<apex:page Controller="AccountList" sidebar="false" standardStylesheets="true"

 <apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:CommandButton action="{!TRStatusSet}" value="Set Transfer Status"/>
<apex:CommandButton action="{!Cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!EligibleAccts}" var="acc" >

....PageBlockTable columns

</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>

 

</apex:page>

 

 

So, this doesn't work. The page loads as a blank white page.

 

So I'm not sure of the best method for doing this, and none of my attempts have worked. I suspect this is due to my lack of understanding of JavaScript, which I am learning slowly. Maybe an answer to this will help.

 

So, should I

1) Try to use an 'action' process on the <apex:page> that could redirect, if I can create a conditional statement at that point in the code

2) Tweak my constructor method to make the above process work?

3) Adapt the link that calls the page - currently I'm just using a URL for the Custom Link. I believe I've seen an OnClick JavaScript syntax before which can direct the user to a different page, but can I access the controller's getEligibleAccts method to check for a result before I set which VF Page to sned the user???

 

Any help is appreciated

 

ODB

 

 

 

 

Hi Friends,

 

I have a small requirement , please let me know whether it is a valid one or not.

 

I am displaying  Account Contacts using a relatedlist in a Visual force page(Standard Controller to Account object Extensions a class) , in which for a certain role like CEO i should not allow the contact to be get deleted . I have to do this using related list(not by other means such as a table datalist) , so i have overriden the del action of Contact object with a visual force page and i am calling a action method on it page load.

 

I am able to check the CEO record and stop the record from getting delete, but my requirement is to display a message  to the user that the record cannot be deleted. 

 

I am ok with custom confirm message (Are you sure?), just need to throw an exception in the visual force from which the del action commensed.

 

I have tried using trigger on before delete for Contact object, but the error message should be displayed on the VFP.

 

Please let me know how this can be done,or i am thinking in a wrong direction

 

Regards,

 

 

  • December 15, 2009
  • Like
  • 0

Hi,

 

Is it possible to replace the home screen with visualforce page ?

so when the very first time after we login, it will go to vf page directly.

Thanks,

  • April 13, 2010
  • Like
  • 0

Hi,

 

I'm trying to connect JQuery with Visualforce component ( eg. Apex:InputText ), but not able to get ID in VF component to use in the JQuery function.

Please help!

 

Thanks

  • April 08, 2010
  • Like
  • 0

Hi,

 

How to control the value in customize table (dashboard) , for column 3 and column 4 ?

for example if column 1 is the grouping by ( eg. Opportunity Owner ), column 2 is sum of contract value,

is it posibble to  show Opportunity Name in column 3 and stage in column 4 ?

  • February 25, 2010
  • Like
  • 0

Is there any solution to make InputTextArea(Long) as word-wrap ?

 

cheers,


 

 

  • December 18, 2009
  • Like
  • 0

Hi,

 

Is it possible to replace the home screen with visualforce page ?

so when the very first time after we login, it will go to vf page directly.

Thanks,

  • April 13, 2010
  • Like
  • 0

Hi,

 

I'm trying to connect JQuery with Visualforce component ( eg. Apex:InputText ), but not able to get ID in VF component to use in the JQuery function.

Please help!

 

Thanks

  • April 08, 2010
  • Like
  • 0

I have a VF Page where the constructor access a get method which queries a list of Accounts for display in a PageBlockTable.

 

If the list gets loaded, the page displays correctly with the table of Accounts.

 

However, if no Accounts are loaded from the query, the page is blank. What I want to do is redirect to a different page with a message saying No Accounts are available with a button to return back to another page. 

 

I haven't been able to figure how to add this redirect though. 

 

I have a PageReference method which is set correctly, and the constructor reads

 

 

public class AccountList { public AccountList() { EligibleAccts = getEligibleAccts(); if (getEligibleAccts().isEmpty()) { NoEligibleAccts(); } system.debug('EligibleAccts size is '+EligibleAccts.size()); }

 

public Account[] getEligibleAccts()

{

  EligibleAccts = [QUERY];
return EligibleAccts;

} public Pagereference NoEligibleAccts() { PageReference PR = new PageReference('/apex/NoEligibleAccts'); PR.setRedirect(true); }

 

 THE PAGE CODE

 

<apex:page Controller="AccountList" sidebar="false" standardStylesheets="true"

 <apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:CommandButton action="{!TRStatusSet}" value="Set Transfer Status"/>
<apex:CommandButton action="{!Cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!EligibleAccts}" var="acc" >

....PageBlockTable columns

</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>

 

</apex:page>

 

 

So, this doesn't work. The page loads as a blank white page.

 

So I'm not sure of the best method for doing this, and none of my attempts have worked. I suspect this is due to my lack of understanding of JavaScript, which I am learning slowly. Maybe an answer to this will help.

 

So, should I

1) Try to use an 'action' process on the <apex:page> that could redirect, if I can create a conditional statement at that point in the code

2) Tweak my constructor method to make the above process work?

3) Adapt the link that calls the page - currently I'm just using a URL for the Custom Link. I believe I've seen an OnClick JavaScript syntax before which can direct the user to a different page, but can I access the controller's getEligibleAccts method to check for a result before I set which VF Page to sned the user???

 

Any help is appreciated

 

ODB

 

 

 

 

Hey guys,

 

I'm trying to add a number of days calculation in my Visualforce page, and this calculation is basically counting the number of days left to the end of a process.

 

I'm working with a date/time field, axns.Finish_date_time__c, so I use the ROUND() function to calculate the number of days only.

 

Here is the formula that I use to calculate the number of days left for my process:

 

ROUND(axns.Finish_date_time__c-DATEVALUE(NOW()),0)

 

This formula works well, but for some reason when it is equal to 10 days it shows the number in the following manner: 1E+1

 

 

Is there a way to display this number as 10?

 

 

Thank you,

 

Behzad

  • March 17, 2010
  • Like
  • 0

Hey all,

 

I have a custom button that redirects to a VF page.

This page and its controller are allowed for the profile of the user.

Also the page security and class security allow this profile as well.

Yet still I'm getting insuficient access for my user that is trying to click the button.

 

 Thanks.

Hi All,

 

How can I find out Id of a particular report , which is created from a custom report type.

 

 

Thanks,

Sridhar 

Hello,

 

I'm trying to create a simple trigger that will add a hyphen to a custom field. I am using the following code for the trigger:

 

trigger MyTrigger on My_Object__c (before insert, before update) {
for (Integer i=0;i<Trigger.new.size();i++) {
String tmp = Trigger.new[i].My_Field__c;
if ((tmp != null) && (tmp.length() == 9)) {
tmp = tmp.substring(0,3)+'-'+tmp.substring(3,5);
Trigger.new[i].My_Field__c = tmp;
}
}
}

 

And I have the following test case, which runs fine with 0 lines not tested, 100% covered:

 

public with sharing class TestCase {
public static testMethod void testMyTrigger() {
My_Object__c someObject = new My_Object__c();
someObject.Name = 'testing';
insert someObject;
someObject.My_Field__c = '12345';
update someObject;

My_Object__c out = [select My_Field__c from My_Object__c where Id = :someObject.Id];
System.assertEquals('123-45', out.My_Field__c);
}
}

 

And when I try to save in Eclipse 3.4.2 with Salesforce plugin version 16.0.0.200906151227 I get the "Unable to perform save on all files" error. If I comment out the line in the trigger with the substring(), it saves fine. If I uncomment it, I get the error again. What is going on?

Message Edited by Nyssa on 03-09-2010 10:45 PM
  • March 09, 2010
  • Like
  • 0

I am trying to insert a custom setting for a user as such

 

MySetting__c x = new MySetting__c(); x.name = 'blfd'; x.setupOwnerId = UserInfo.getUserId(); insert(x);

 

 The error I get is "System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: SetupOwnerId (id value of incorrect type): [SetupOwnerId]"

 

  • March 08, 2010
  • Like
  • 0

Apex Governor limit document states "In a SOQL query with parent-child relationship sub-queries, each parent-child relationship counts as an additional query. These types of queries have a limit of three times the number for top-level queries."

 

1) Referring to "In a SOQL query with parent-child relationship sub-queries, each parent-child relationship counts as an additional query." If i execute following query, the no of SOQL executed needs to be Three. Yet debug log shows me 1 Query (and not 3). Am I missing anything?

List<Account> a =[Select Id, (Select Id from Contacts),(Select Id from Cases) from Account];


2) Can someone elaborate more on what does "These types of queries have a limit of three times the number for top-level queries." means?

This is pretty simple although I am a complete newb to triggers and Apex code. I have a field "Contact18Dig" on the Contact object that I am trying to populate the 18 digit contact id to. Any time a new contact is created or the "Contact18Dig" field is modified, I want the "Contact18Dig" field to populate with the full contact ID. If I create a contact and then edit the record, this code works fine. But, it is not inserting the 18 digit contact upon creating a new contact.

 

Any assitance, guidance, or corrected code examples are much appreciated.

 

trigger ContactID18Digit on Contact (before insert, before update) { for(Contact c : Trigger.new) { if(c.Contact18Dig__c != c.id) { c.Contact18Dig__c = c.id; } } }

 

So, I have a list of Territories associated with Accounts.

 

The list has only two Territories, and I want to list their names in a pageBlockTable.

 

I am cycling through a list of AccountUIElements - a class I created to be able to store Territories with their associated Accounts so I could iterate through one list and reference both objects.

 

system.debug statements already confirm that there are only two Territory values in the AccountUIElement's 'AccTerrs' territory list = one for 'Western 5', another for 'Inside 1'. The page has the following code:

 

<apex:pageBlockTable value="{!UIAccts}" var="UIA" columns="6" columnswidth="10,10,15,35,10,10">

...other columns which display correctly...

<apex:column headervalue="Current Territories" id="AccTerrs" > <apex:panelgrid columns="1"> <apex:repeat value="{!UIA.AccTerrs}" var="terr"> <apex:outputText value="{!terr.Name} " /> </apex:repeat> <apex:panelgrid> <apex:column>

</apex:pageBlockTable>

The page displays this column as 'Western 5 Inside 1 Western 5 Inside 1'. Again the AccTerrs list only has the two Territories, and the process only appears to be running once according to the debug log (otherwise the other columns would be displaying with duplicate values??).

 

Any ideas on why this is happening, and how I can prevent it???

 

Thanks

 

ODB


Hi all, I've been programming in Apex/VisualForce for the past couple of weeks, just getting used to everything, and I've hit a bit of a roadblock.


I'm trying to generate a Google Chart from company statistics that we track and aggregate into reports and dashboards. On the particular dashboard is a very simple VisualForce page.



I'm putting some code in here, but the server continually times out when I hit Preview so I apologize if it doesn't look too good below.



I have this visualforce page:



<apex:page controller="MyStatsController" action="{!MyStatsController}">

<apex:image url="{!ReturnedURLFromController}"></apex:image>

</apex:page>





Next is my controller:




public class MyStatsController {

   String ReturnedURLFromController;

   List data;



   public void MyStatsController()

   {

      String cid = System.currentPageReference().getParameters().get('cid');

      Data = [Select ... where company_id =: cid ];

      ...

      ReturnedURLFromController = GenerateChartURL();

   }



   public string GenerateChartURL(){

      //Works on data to make the google chart url

      return chart_url;

   }

 }





This is my problem line:



String cid = System.currentPageReference().getParameters().get('cid');



When I open the Dashboard page from a custom link, the url resembles this:
https://na2.salesforce.com/01C50000000Bds1?cid=someCompanyId

 

But no matter what I do, my controller is finding cid as null. I have a check after cid gets assigned and if its still NULL after the getParameter().get()  call, it loads bogus data and changes the chart's title to a warning message, and this is what I get everytime.

 

If anyone can point me in the right direction here, I would really appreciate it.

I'm working on some unit test coverage code and currently have 77% of the controller covered.  I'm trying to get the remaining lines covered before adding my assert statements.

 

The lines missing code coverage are in my save() method (see the screenshot below).

 

In my test method, I've initialized the controller and passed in a new instance of the StandardSetController with a list of the sObject being used.  I have called all the properties and methods in the controller.

 

Can anyone provide some help on how I can get the missing lines in my save method covered?  I need to create a new task to use in the save method that is being attached to multiple records.

 

Here is my controller code:

 

public class MassAddActivityController { private List<Service_Delivery__c> sds; private Task assignedTo = new Task(); private Task status = new Task(); private Task activityDate = new Task(); private Task clientAttendees = new Task(); private Task hsgAttendees = new Task(); private Task presenter = new Task(); private Task purpose = new Task(); private Task dynamics = new Task(); private Task outcomes = new Task(); private Task description = new Task(); private Task sendContactReport = new Task(); private Boolean render; private Integer count; public Task task {get; set;} public Task getAssignedTo() { return assignedTo; } public Task getStatus() { return status; } public String subject { get; set; } public Task getActivityDate() { return activityDate; } public Task getClientAttendees() { return clientAttendees; } public Task getHsgAttendees() { return hsgAttendees; } public Task getPresenter() { return presenter; } public Task getPurpose() { return purpose; } public Task getDynamics() { return dynamics; } public Task getOutcomes() { return outcomes; } public Task getDescription() { return description; } public Task getSendContactReport() { return sendContactReport; } public MassAddActivityController(ApexPages.StandardSetController stdSetController) { init((List<Service_Delivery__c>) stdSetController.getSelected()); status.status = 'Completed'; subject = 'Presentation/Meeting'; assignedTo.OwnerId = UserInfo.getUserId(); DateTime dt = System.now(); Date currentDate = date.newinstance(dt.year(), dt.month(), dt.day()); activityDate.activityDate = currentDate; render = false; } public void init(List<Service_Delivery__c> sds) { List<Id> ids = new List<Id>(); for (Service_Delivery__c sd : sds) { ids.add(sd.id); } this.sds = [Select Id, Name From Service_Delivery__c Where Id in :ids]; count = [Select Count() From Service_Delivery__c Where Id in :ids]; } public Id getRecordTypeId() { RecordType rt = [Select Id From RecordType WHERE Name = 'Contact Reports Entry']; Id recordTypeId = rt.Id; return recordTypeId; } public List<Service_Delivery__c> getServiceDeliveries() { return sds; } public List<SelectOption> getItems() { Schema.DescribeFieldResult pklst = Schema.Task.Subject.getDescribe(); List<Schema.PicklistEntry> ple = pklst.getPicklistValues(); List<SelectOption> options = new List<SelectOption>(); for(Schema.PicklistEntry f : ple) { options.add(new SelectOption(f.getLabel(), f.getLabel())); } return options; } public PageReference save() { try { for (Service_Delivery__c sd : sds) { Task t = new Task(); t.recordTypeId = getRecordTypeId(); t.ownerId = assignedTo.OwnerId; t.status = 'Completed'; t.subject = subject; t.activityDate = activityDate.activityDate; t.whatId = sd.Id; t.Client_Company_Attendees__c = clientAttendees.Client_Company_Attendees__c; t.Health_Strategies_Group_Attendees__c = hsgAttendees.Health_Strategies_Group_Attendees__c; t.Meeting_Presenter__c = presenter.Meeting_Presenter__c; t.Purpose__c = purpose.Purpose__c; t.Dynamics__c = dynamics.Dynamics__c; t.Outcomes__c = outcomes.Outcomes__c; t.description = description.description; t.Send_Contact_Report__c = sendContactReport.Send_Contact_Report__c; t.Mass_Added_Date__c = Date.today(); insert t; } ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Activities added successfully.'); ApexPages.addMessage(msg); render = true; return null; } catch (Exception ex) { ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.addMessage(errMsg); return null; } } public boolean getRendered() { return render; } public Integer getCount() { return count; } static testMethod void test() { List<Service_Delivery__c> sds = [Select id, name From Service_Delivery__c LIMIT 5]; MassAddActivityController ctrl = new MassAddActivityController(new ApexPages.StandardSetController(sds)); ctrl.getAssignedTo(); ctrl.getStatus(); ctrl.getActivityDate(); ctrl.getClientAttendees(); ctrl.getHsgAttendees(); ctrl.getPresenter(); ctrl.getPurpose(); ctrl.getDynamics(); ctrl.getOutcomes(); ctrl.getDescription(); ctrl.getSendContactReport(); ctrl.getCount(); ctrl.getRendered(); ctrl.getRecordTypeId(); ctrl.getServiceDeliveries(); ctrl.getItems(); ctrl.save(); } }

 

screenshot

screenshot

Hi All,

 

I have been trying to find the cause of this issue since long and still dont have a clue about it. :(

 

I have a custom object on which some trigger is written. The code sends an email to user when a new record is created, using workflow. This works smoothly but when APEX test case is executed, it shows an error message and test cases fails. The error looks like : Internal Salesforce Error: 791389547-89 (-1559824086) (-1559824086)

 

Deactivating the worklflow makes this works fine. I have tried all the combinations of workflow values and a blank email template as well.

 

Is there any limitation in Salesforce on workflows and emails. Please suggest. 

  • December 20, 2009
  • Like
  • 0

Hi, I was wonder if you can add your own block of information onto the standard contacts page. I like what is on there already but I do not want to override the page but add a section on the page. 

 

Thanks for any help you can give. 

I have a custom Quote object and this has a line item related list linked to it with the quote products. I have created a visualforce page displaying a table of the products linked to the quote. On this page i want to be able to edit the values, e.g. price of the product. I have then put a save button on the visualforce page. However when you click save it goes back to the quotes page but the values on the line items havnt been updated.

 

 

<apex:page standardController="Quotes__c" > <apex:form > <apex:pageBlock mode="edit"> <apex:pageBlockSection Title="Update Products Pricing & Quantities"> <table border="0" width="100%" id="table4"> <tr> <td bgcolor="#C0C0C0"><font face="Arial">Product</font></td> <td bgcolor="#C0C0C0"><font face="Arial">Price</font></td> <td bgcolor="#C0C0C0"><font face="Arial">Quantity</font></td> </tr> <apex:repeat value="{!Quotes__c.Line_Items__r}" var="line"> <tr> <td><apex:InputField value="{!line.Product__r.Name}"/></td> <td><apex:InputField value="{!line.Unit_Price__c}"/></td> <td><apex:InputField value="{!line.Units_Sold__c}"/></td> </tr> </apex:repeat> </table> </apex:pageBlockSection> <apex:commandButton action="{!save}" value="Update"/> </apex:pageBlock> </apex:form> </apex:page>

 This is the code for my visualforce page. 

Can someone let me know why the values are not being saved and updated on the quote page.

 Many thanks,

 

Matt

 

 

This is the first time I have played with Salesforce.  I am trying to figure out are there any resources/previous threads discussing owner relationships.  I am trying to have an owner field default always to one specific value no matter what.  

 

I apologize for my lack of knowledge but this is my first time scripting/playing with Salesforce.