• megsuma
  • NEWBIE
  • 0 Points
  • Member since 2010

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

Hi all,

 

 I have a bit of a problem that probably shouldn't be a problem...I'm trying to do something that should be alot easier than it has been so far:

 

 I have a field being populated by a formula and the field is either a 1 or a 0 depending on the outcome of the formula. All I want is for a picklist to change value when the field's value changes.

 

Here is my trigger:

 

trigger CompanyGoalUpdate on Company_Goal__c (after insert, after update) {
	Company_Goal__c cmp = [SELECT Upcoming_Goal__c, Use_on_Company__c, LastModifiedDate FROM Company_Goal__c WHERE Id =: trigger.new[0].Id];
	
	if(cmp.Upcoming_Goal__c == 1)
		cmp.Use_on_Company__c = 'Use';
	else
		cmp.Use_on_Company__c = 'Do Not Use';
	
	DateTime RightNow = System.now();
	
	if(cmp.LastModifiedDate < RightNow.addMinutes(-30))
		update cmp;
}

 

Any thoughts?

 

Hi all, once again Apex has left me scratching my head. I have a trigger that I'm trying to test, here is my test method for that trigger:

 

 

	static testMethod void testCompanyGoalUpdate(){
		Company_Goal__c cmp = new Company_Goal__c();
		Company__c myCompany = new Company__c();
		cmp.Test__c = 'Test';
		cmp.Company__c = myCompany.Id;
		System.debug(cmp);
		insert cmp;
		delete cmp;		
	}

 Eclipse tells me:

 

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Company__c]: [Company__c]

 

In the snippet above I was sure I set Company__c properly with "cmp.Company__C = ..."

 

I am definitely open to suggestions, I'm not even sure I'm writing the test method quite right as this is my first test method for a trigger (after insert, after update).

 

 

 

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Company__c]: [Company__c]

Man, once you start programming for Salesforce you really realize what a pain it can be moving from a weak-typed language (cough PHP) to a strongly typed language like Apex. Trying to replicate the familiar behavior of nested arrays in Apex has proven to be quite difficult.

 

So, I have a nested map defined:

 

 

Map<String, Map<String, List<Decimal>>> return_data = new Map<String, Map<String, List<Decimal>>>();

 

 Further down in my code, I'm attempting to loop this map with a for loop:

 

for(Map<String, Map<String, List<Decimal>>> c_data : return_data) { ... }

 

However, the server complains:

 

 

Save error: Loop must iterate over a collection type: MAP:String,MAP:String,LIST:Decimal 

 

What am I missing here?

 

Is it possible to pass a parameter to an Apex page without the user having to perform an action (such as clicking a button or link)? Essentially, the idea would be to have a VF page that takes a parameter from the query string and passes it to the apex controller when my getter function is called. Page is something like this:

 

<apex:page controller="CompanyStatsDashboardController"> ...Some javascript to get the query string parameter... <apex:image url="{!UserCountChart}"></apex:image> </apex:page>

 The reason I can't just call something like System().currentPageReference().getParameters().get() is because the VF page lives on a Dashboard, and as such renders in an iFrame. The iFrame has it's own URL that does not contain the parameter, and as far as I can tell you can't tell the Dashboard to pass parameters to the VF page. I've also tried setting an <apex:param> with the value I want to pass and using apexPages().currentPage().getParameters(), but this doesn't work either. 

 

 


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.

Hi all,

 

 I have a bit of a problem that probably shouldn't be a problem...I'm trying to do something that should be alot easier than it has been so far:

 

 I have a field being populated by a formula and the field is either a 1 or a 0 depending on the outcome of the formula. All I want is for a picklist to change value when the field's value changes.

 

Here is my trigger:

 

trigger CompanyGoalUpdate on Company_Goal__c (after insert, after update) {
	Company_Goal__c cmp = [SELECT Upcoming_Goal__c, Use_on_Company__c, LastModifiedDate FROM Company_Goal__c WHERE Id =: trigger.new[0].Id];
	
	if(cmp.Upcoming_Goal__c == 1)
		cmp.Use_on_Company__c = 'Use';
	else
		cmp.Use_on_Company__c = 'Do Not Use';
	
	DateTime RightNow = System.now();
	
	if(cmp.LastModifiedDate < RightNow.addMinutes(-30))
		update cmp;
}

 

Any thoughts?

 

Is it possible to pass a parameter to an Apex page without the user having to perform an action (such as clicking a button or link)? Essentially, the idea would be to have a VF page that takes a parameter from the query string and passes it to the apex controller when my getter function is called. Page is something like this:

 

<apex:page controller="CompanyStatsDashboardController"> ...Some javascript to get the query string parameter... <apex:image url="{!UserCountChart}"></apex:image> </apex:page>

 The reason I can't just call something like System().currentPageReference().getParameters().get() is because the VF page lives on a Dashboard, and as such renders in an iFrame. The iFrame has it's own URL that does not contain the parameter, and as far as I can tell you can't tell the Dashboard to pass parameters to the VF page. I've also tried setting an <apex:param> with the value I want to pass and using apexPages().currentPage().getParameters(), but this doesn't work either. 

 

 


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.