• Marcio Zima.ax1538
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 8
    Replies
Hi everyone,

I have been using the following apex code to select information about Task:

public List<OpenActivity> getOpen()
{
 
  SObject[] Cuenta = [SELECT Name,
           (SELECT Account.Name, What.Name, Who.Name, Account.Id, Id, IsAllDayEvent, OwnerId, CallDurationInSeconds, CallObject, CallDisposition, CallType, Close_task__c, IsClosed, Closed_Date__c, Description, WhoId, CreatedById, CreatedDate, Data_Quality_Description__c, Data_Quality_Score__c, ActivityDate, IsDeleted, DurationInMinutes, LastModifiedById, LastModifiedDate, Location, WhatId, Priority, ReminderDateTime, IsReminderSet, Status, Subject, SystemModstamp, IsTask, ActivityType, WhatIdCode__c FROM OpenActivities)
            From CustomObj__c WHERE id=:cntact.Id];
                   
  Actividades = (List<OpenActivity>)Cuenta.get(0).getSObjects('OpenActivities');

  return Actividades;
}



And my Visualforce Page:


<apex:dataTable value="{!Open}" var="each" cellpadding="10" border="0" styleClass="list">
       <apex:column headerValue="Subject">
        <apex:outputLink value="/{!each.id}?retURL=%2Fapex%2Ftestpage3%3Fid%3D{!id}">
        {!each.Subject}
        </apex:outputLink>
       </apex:column>
       <apex:column headerValue="Name">{!each.Who}</apex:column>
       <apex:column headerValue="Assigned To">{!each.WhatId}</apex:column>
       <apex:column headerValue="Due Date">{!each.ActivityDate}</apex:column>
       <apex:column headerValue="Status">{!each.Status}</apex:column>
       <apex:column headerValue="Priority">{!each.Priority}</apex:column>
       <apex:column headerValue="OwnerId">{!each.OwnerId}</apex:column>
      
      
       <apex:column headerValue="Action">
        <apex:outputLink value="/{!each.id}/e?retURL=%2Fapex%2Ftestpage3%3Fid%3D{!id}">
        Edit
        </apex:outputLink>
        &nbsp;|&nbsp;
        <apex:outputLink value="/{!each.id}/e?close=1&retURL=%2Fapex%2Ftestpage3%3Fid%3D{!id}">
        Close
        </apex:outputLink>
       </apex:column>
      </apex:dataTable>



The problem is that when I try to show the name of the Accounts. It's showing the ID instead of Name. I tried {!each.Who.Name}, but it appeared blank.

User-added image

Any suggestion to solve this?

Hi,

 

I'm trying to code an Apex test class for a Dynamic Related List that add and delete rows in a table through visualforce.

The complete code I got here:

 http://visualforcemadeeasy.blogspot.com.br/2009/03/how-to-add-and-delete-row-in-datatable.html

 

public class AccountsController {

/* I set the Account and Case Objects
here for use through out the code*/
public Account acct { get; private set;}
public Case[] caseItems { get; private set; }
private ApexPages.StandardController controller;

// constructor, loads the Account and
// any cases associated with it

void caseItems(id id) {
acct = [SELECT Id, Name, Type, AccountNumber, Site,
      (SELECT Id, CaseNumber, Status, Reason,Origin,
      Subject FROM Cases) FROM Account
      where id = :id limit 1];
//Hook caseItems to the query above
 caseItems = acct.Cases;
}

//Define the id
id accountid;

/* A List Method to delete the Cases assigned*/
public list todelete = new list();

public AccountsController (ApexPages.StandardController c)
{
/* this will kickoff you main page */
controller = c;
/* to get this current Account Id*/
accountid = c.getRecord().id;
/*kick off the init() function*/
init();
}
public AccountsController () {
accountid =
ApexPages.CurrentPage().getParameters().get('id');

init();

}

void init() {
/* load up Cases
basically we defined caseitems up on top, so
when the page loads then caseItems(accountId)
will go through the query and list out the
Items assoicated with it */
caseItems(accountid);  
}

public PageReference save() {
try {
upsert caseItems;
if ( todelete.size() > 0 ) {           
delete todelete;   
}
caseItems(acct.id);
}
catch ( DmlException exc) {
      ApexPages.addMessages(exc);
      return null;
}
return null;
}


/* your Delete functionality*/
public PageReference del() {

string delnumber =
ApexPages.CurrentPage().getParameters().get('delnumber');

system.assert( delnumber != null );
integer gone = -1;
integer i = 0;
  
for ( i=0; i< casenumber ="="" gone =" i;">= 0) {
todelete.add(caseItems.remove(gone) );
}
return null;
}
public PageReference add() {
// insert a new line, after user clicks Add
Case cs =  new Case(
AccountId = acct.id,
Subject = 'hello', Status = 'Low',
Reason = 'Other',Origin='Low'
);
caseItems.add ( cs );
return null;
 }
}

 

 

 

 

My test class coverage 71%. I'm using custom objects. When I include the function del() - DELETE, it returns the following exception: System.AssertException: Assertion Failed

 

        LineItem__c item = new LineItem__c(ObjectId__c = ag.Id);
        insert item;

        ApexPages.StandardController QContracts_Line = new ApexPages.StandardController(item);
	AccountsController qe = new AccountsController(QContracts_Line);
	ApexPages.currentPage().getParameters().put('id', item.Id);
	qe.add();
	qe.save();
        qe.del();

 

Does anyone knows any way to resolve this?

 

I'm trying to insert a custom clone button on a visualforce page. I found a code that seems what I need, but it's not working

 

<input value="Clone" class="btn" name="Test" 
                onclick="navigateToUrl('/apex/myEditPage?clone=1&id={!Object.id}&retURL=%2F{!Object.id}')" 
                title="Test" type="button" />

 

After the click, it catches values of the fields, but when I click on save, nothing happens It doesn't create a new id with the values of the original record.

 

Any suggestion?

I'm having problem to code the test for the following trigger code that automatically generate relatedlist according to a value of a picklist. Until now it's with 75% code coverage.

 

trigger AddRelatedList on Obj1__c (after update) {
    List<Obj2__c> listRisks = new List<Obj2__c>();
    List<Obj3__c> listChecks = new List<Obj3__c>();
    
    //Assign the context before and after the change into a Map
    Map<Id, Obj1__c> newStatusMap = Trigger.newMap;
	Map<Id, Obj1__c> oldStatusMap = Trigger.oldMap;

	//Loop through the map
	for(Id itemId:newStatusMap.keySet()){
		Obj1__c myNewItem = newStatusMap.get(itemId);
		Obj1__c myOldItem = oldStatusMap.get(itemId);
		
		if (myNewItem.F_O__c <> myOldItem.F_O__c){
		    for (Obj1__c a : Trigger.new) {
		    	if(a.F_O__c == 'Firm'){        
			        Obj2__c clt = new Obj2__c(Line_Item__c = a.Id);
			        listRisks.add(clt);
			        
			        Obj3__c clt2 = new Obj3__c(Line_Item__c = a.Id);
			        listChecks.add(clt2);
		        }
		    }		   
		 }
	}
    insert listRisks;
    insert listChecks;
}

 It's with these 4 lines not tested:

 

Obj2__c clt = new Obj2__c(Line_Item__c = a.Id);
listRisks.add(clt);
			        
Obj3__c clt2 = new Obj3__c(Line_Item__c = a.Id);
listChecks.add(clt2);

 

Anyone knows how to help?

 

Hi,

 

I have a Visualforce Chart that is with the following tag:

 

<apex:barSeries gutter="80" colorSet="red, yellow" title="Test1, Test2" stacked="false" orientation="vertical" axis="right" xField="name" yField="millionsRegion,targetRegionM">

 

The color of the bars is working well when I first load the visualforce page, but when I click to hide some data it is changing the color to the standard color of chart (blue and green).

 

Anyone ever had this problem?

 

 

 

I'm trying to cover the following trigger:

public PageReference redirect() {
  Profile p = [select name from Profile where id = 
			   :UserInfo.getProfileId()];
  if ('Manager'.equals(p.name) 
	  || 'Client'.equals(p.name)) 
	  {
	   PageReference customPage =  Page.info;
	   customPage.setRedirect(true);
	   customPage.getParameters().put('id', recordId);
	   return customPage;
	  } else {
		  return null; //otherwise stay on the same page  
	
	  }
   }

 

At the moment  my following test class has been covering 63% of the code:

static testMethod void testoverrideCon() {

Profile pr = [select name from Profile where id = 
			   '00e34200001nqX5'];
Apexpages.StandardController stdController = new Apexpages.StandardController(new Profile()); 
    overrideCon testPRTC = new overrideCon(stdController);

    testPRTC.redirect();
    

  }

 I'm having problem to cover these specific lines:

if ('Manager'.equals(p.name) 
	  || 'Client'.equals(p.name)) 
	  {
	   PageReference customPage =  Page.info;
	   customPage.setRedirect(true);
	   customPage.getParameters().put('id', recordId);
	   return customPage;

 

Anyone have any suggestion to solution?

 

Thanks

 

 

I have one visualforce page that will display more than 500 fields. When it has around 400 fields it was working well.

But as I include more fields it returned the following error: "SOQL statements can not be longer than 10000 characters".

 

I tried to insert a visualforce page into another page and it returned the same error.

 

Are there some way to do it work? Many fields in the same visualforce page without problems with SOQL?

I'm using many formulas like that:

 

IF(Payment_01__c = TRUE, 1, 0)
+ IF(Payment_02__c = TRUE, 4, 0)
+ IF(Payment_03__c = TRUE, 16, 0)

 

Payment is a checkbox. There are many other checkbox in the object with the same formula. And there is a Total that is the final sum of all thing. But I'm receiving this message:

Error: Compiled formula is too big to execute (5,371 characters). Maximum size is 5,000 characters

 

How can I solve it?

There is a formula field "Y__c" that returns 'High', 'Medium' and 'Low'. It's using a workflow rule calculation that evaluate when It's saved.

 

I need a Chart with color red (high), yellow (medium) and green (low). So I create a picklist to set the colors. This picklist have a field update and a workflow to each status that set the value according to "Y__c".

 

The problem is the execution order of workflows. Picklist field is not updating in the same time of "Y__c". Just after a second click on save. How to set pick list value automatically in this case to use Chart? Apex?

I'm using a field formula text that returns HIGH, MEDIUM or LOW. 

 

Now I'm having problems to show the colors (HIGH=red, MEDIUM=yellow, LOW=green) on a Visualforce chart.

 

The code is:

 

<apex:pieSeries dataField="value" labelField="label" colorset="#ff0000, #00dd00, #ffff00" />

 

 

It's working when there are data to high, medium and low status. When there are just medium and low, on chart appears red and yellow. When there is just low status, for example, appears just red color.

 

How can I fix a color to each status and not to show in order like in this parameters of Visualforce chart?

Hi everyone,

I have been using the following apex code to select information about Task:

public List<OpenActivity> getOpen()
{
 
  SObject[] Cuenta = [SELECT Name,
           (SELECT Account.Name, What.Name, Who.Name, Account.Id, Id, IsAllDayEvent, OwnerId, CallDurationInSeconds, CallObject, CallDisposition, CallType, Close_task__c, IsClosed, Closed_Date__c, Description, WhoId, CreatedById, CreatedDate, Data_Quality_Description__c, Data_Quality_Score__c, ActivityDate, IsDeleted, DurationInMinutes, LastModifiedById, LastModifiedDate, Location, WhatId, Priority, ReminderDateTime, IsReminderSet, Status, Subject, SystemModstamp, IsTask, ActivityType, WhatIdCode__c FROM OpenActivities)
            From CustomObj__c WHERE id=:cntact.Id];
                   
  Actividades = (List<OpenActivity>)Cuenta.get(0).getSObjects('OpenActivities');

  return Actividades;
}



And my Visualforce Page:


<apex:dataTable value="{!Open}" var="each" cellpadding="10" border="0" styleClass="list">
       <apex:column headerValue="Subject">
        <apex:outputLink value="/{!each.id}?retURL=%2Fapex%2Ftestpage3%3Fid%3D{!id}">
        {!each.Subject}
        </apex:outputLink>
       </apex:column>
       <apex:column headerValue="Name">{!each.Who}</apex:column>
       <apex:column headerValue="Assigned To">{!each.WhatId}</apex:column>
       <apex:column headerValue="Due Date">{!each.ActivityDate}</apex:column>
       <apex:column headerValue="Status">{!each.Status}</apex:column>
       <apex:column headerValue="Priority">{!each.Priority}</apex:column>
       <apex:column headerValue="OwnerId">{!each.OwnerId}</apex:column>
      
      
       <apex:column headerValue="Action">
        <apex:outputLink value="/{!each.id}/e?retURL=%2Fapex%2Ftestpage3%3Fid%3D{!id}">
        Edit
        </apex:outputLink>
        &nbsp;|&nbsp;
        <apex:outputLink value="/{!each.id}/e?close=1&retURL=%2Fapex%2Ftestpage3%3Fid%3D{!id}">
        Close
        </apex:outputLink>
       </apex:column>
      </apex:dataTable>



The problem is that when I try to show the name of the Accounts. It's showing the ID instead of Name. I tried {!each.Who.Name}, but it appeared blank.

User-added image

Any suggestion to solve this?

I'm trying to insert a custom clone button on a visualforce page. I found a code that seems what I need, but it's not working

 

<input value="Clone" class="btn" name="Test" 
                onclick="navigateToUrl('/apex/myEditPage?clone=1&id={!Object.id}&retURL=%2F{!Object.id}')" 
                title="Test" type="button" />

 

After the click, it catches values of the fields, but when I click on save, nothing happens It doesn't create a new id with the values of the original record.

 

Any suggestion?

Hi,

 

I'm trying to code an Apex test class for a Dynamic Related List that add and delete rows in a table through visualforce.

The complete code I got here:

 http://visualforcemadeeasy.blogspot.com.br/2009/03/how-to-add-and-delete-row-in-datatable.html

 

public class AccountsController {

/* I set the Account and Case Objects
here for use through out the code*/
public Account acct { get; private set;}
public Case[] caseItems { get; private set; }
private ApexPages.StandardController controller;

// constructor, loads the Account and
// any cases associated with it

void caseItems(id id) {
acct = [SELECT Id, Name, Type, AccountNumber, Site,
      (SELECT Id, CaseNumber, Status, Reason,Origin,
      Subject FROM Cases) FROM Account
      where id = :id limit 1];
//Hook caseItems to the query above
 caseItems = acct.Cases;
}

//Define the id
id accountid;

/* A List Method to delete the Cases assigned*/
public list todelete = new list();

public AccountsController (ApexPages.StandardController c)
{
/* this will kickoff you main page */
controller = c;
/* to get this current Account Id*/
accountid = c.getRecord().id;
/*kick off the init() function*/
init();
}
public AccountsController () {
accountid =
ApexPages.CurrentPage().getParameters().get('id');

init();

}

void init() {
/* load up Cases
basically we defined caseitems up on top, so
when the page loads then caseItems(accountId)
will go through the query and list out the
Items assoicated with it */
caseItems(accountid);  
}

public PageReference save() {
try {
upsert caseItems;
if ( todelete.size() > 0 ) {           
delete todelete;   
}
caseItems(acct.id);
}
catch ( DmlException exc) {
      ApexPages.addMessages(exc);
      return null;
}
return null;
}


/* your Delete functionality*/
public PageReference del() {

string delnumber =
ApexPages.CurrentPage().getParameters().get('delnumber');

system.assert( delnumber != null );
integer gone = -1;
integer i = 0;
  
for ( i=0; i< casenumber ="="" gone =" i;">= 0) {
todelete.add(caseItems.remove(gone) );
}
return null;
}
public PageReference add() {
// insert a new line, after user clicks Add
Case cs =  new Case(
AccountId = acct.id,
Subject = 'hello', Status = 'Low',
Reason = 'Other',Origin='Low'
);
caseItems.add ( cs );
return null;
 }
}

 

 

 

 

My test class coverage 71%. I'm using custom objects. When I include the function del() - DELETE, it returns the following exception: System.AssertException: Assertion Failed

 

        LineItem__c item = new LineItem__c(ObjectId__c = ag.Id);
        insert item;

        ApexPages.StandardController QContracts_Line = new ApexPages.StandardController(item);
	AccountsController qe = new AccountsController(QContracts_Line);
	ApexPages.currentPage().getParameters().put('id', item.Id);
	qe.add();
	qe.save();
        qe.del();

 

Does anyone knows any way to resolve this?

 

I'm having problem to code the test for the following trigger code that automatically generate relatedlist according to a value of a picklist. Until now it's with 75% code coverage.

 

trigger AddRelatedList on Obj1__c (after update) {
    List<Obj2__c> listRisks = new List<Obj2__c>();
    List<Obj3__c> listChecks = new List<Obj3__c>();
    
    //Assign the context before and after the change into a Map
    Map<Id, Obj1__c> newStatusMap = Trigger.newMap;
	Map<Id, Obj1__c> oldStatusMap = Trigger.oldMap;

	//Loop through the map
	for(Id itemId:newStatusMap.keySet()){
		Obj1__c myNewItem = newStatusMap.get(itemId);
		Obj1__c myOldItem = oldStatusMap.get(itemId);
		
		if (myNewItem.F_O__c <> myOldItem.F_O__c){
		    for (Obj1__c a : Trigger.new) {
		    	if(a.F_O__c == 'Firm'){        
			        Obj2__c clt = new Obj2__c(Line_Item__c = a.Id);
			        listRisks.add(clt);
			        
			        Obj3__c clt2 = new Obj3__c(Line_Item__c = a.Id);
			        listChecks.add(clt2);
		        }
		    }		   
		 }
	}
    insert listRisks;
    insert listChecks;
}

 It's with these 4 lines not tested:

 

Obj2__c clt = new Obj2__c(Line_Item__c = a.Id);
listRisks.add(clt);
			        
Obj3__c clt2 = new Obj3__c(Line_Item__c = a.Id);
listChecks.add(clt2);

 

Anyone knows how to help?

 

Hi,

 

I have a Visualforce Chart that is with the following tag:

 

<apex:barSeries gutter="80" colorSet="red, yellow" title="Test1, Test2" stacked="false" orientation="vertical" axis="right" xField="name" yField="millionsRegion,targetRegionM">

 

The color of the bars is working well when I first load the visualforce page, but when I click to hide some data it is changing the color to the standard color of chart (blue and green).

 

Anyone ever had this problem?

 

 

 

I'm trying to cover the following trigger:

public PageReference redirect() {
  Profile p = [select name from Profile where id = 
			   :UserInfo.getProfileId()];
  if ('Manager'.equals(p.name) 
	  || 'Client'.equals(p.name)) 
	  {
	   PageReference customPage =  Page.info;
	   customPage.setRedirect(true);
	   customPage.getParameters().put('id', recordId);
	   return customPage;
	  } else {
		  return null; //otherwise stay on the same page  
	
	  }
   }

 

At the moment  my following test class has been covering 63% of the code:

static testMethod void testoverrideCon() {

Profile pr = [select name from Profile where id = 
			   '00e34200001nqX5'];
Apexpages.StandardController stdController = new Apexpages.StandardController(new Profile()); 
    overrideCon testPRTC = new overrideCon(stdController);

    testPRTC.redirect();
    

  }

 I'm having problem to cover these specific lines:

if ('Manager'.equals(p.name) 
	  || 'Client'.equals(p.name)) 
	  {
	   PageReference customPage =  Page.info;
	   customPage.setRedirect(true);
	   customPage.getParameters().put('id', recordId);
	   return customPage;

 

Anyone have any suggestion to solution?

 

Thanks

 

 

I have one visualforce page that will display more than 500 fields. When it has around 400 fields it was working well.

But as I include more fields it returned the following error: "SOQL statements can not be longer than 10000 characters".

 

I tried to insert a visualforce page into another page and it returned the same error.

 

Are there some way to do it work? Many fields in the same visualforce page without problems with SOQL?

I'm using many formulas like that:

 

IF(Payment_01__c = TRUE, 1, 0)
+ IF(Payment_02__c = TRUE, 4, 0)
+ IF(Payment_03__c = TRUE, 16, 0)

 

Payment is a checkbox. There are many other checkbox in the object with the same formula. And there is a Total that is the final sum of all thing. But I'm receiving this message:

Error: Compiled formula is too big to execute (5,371 characters). Maximum size is 5,000 characters

 

How can I solve it?

Hi,

 

Hats off to Jeff Douglas for this wonderful piece of work. I've use it successfully more or less as is.

http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/

 

I now have a search that really needs to be button driven, partly from a combo of fast typing and huge amount of data.

 

It seemed to me that "all I had to do" was:

  • Create a button with onclick="doSearch();"
  • Remove onkeyup="doSearch();" from the search criteria fields
  • fill the fields and click the button

Clearly not. I have gotten mixed results. The search doesn't happen. Sometimes it appears that the page is re-entered after the search is done and the page is rendered. That is,

  • fill the fields and click the button
  • Page is rerendered
  • Page is rerendered again

I can see this in the logs. The soql string has the search parameters: "and Contributor__r.firstname LIKE 'ag%"

 

Moreover, if I have a "mixed" page with the button and the onkeyups the search works.

 

Any experience with changing Jeff's code to button click? Any ideas what I am doing wrong?

 

Thanks in advance... Bob