• jonathanrico.
  • NEWBIE
  • 55 Points
  • Member since 2008


  • Chatter
    Feed
  • 2
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 31
    Questions
  • 78
    Replies

Test coverage in my package is failing! It seems to be failing on blank lines, closing brackets, random lines in queries and comments. Causing my code coverage to be half (or less) than what it should be!

 

None of this should be scanned.

 

Anyone else getting this problem?

Hi

 

My stuck with this feature:

 

I need to Relate (Connect) a ContentVersion object (A file I retrive from an email) I create in my Apex code to a custom object I have in the database.

 

The GUI feature that allows to do that has a Related To lookup filed but I can't find how to do this in APEX.

 

I appricate an advise

 

Thanks

 

 

I have found some info out there about Mixed_DML errors, but most of them have to do with Controllers and action chaining for VF pages. 

 

I am getting one on a trigger that attempts to do the following:

 

Up until this point every employee gets a seat in our SFDC org. We also make a Contact record for every employee to record cases, training etc. Therefore, I wanted to make a trigger that created a Contact whenever a new User record is created or upates the Contact whenever the corresponding User is edited. So the following is what I started with. The logic isn't complete, but there is enough there to get started. Anyway. it's giving me the following when I try to test by creating a new user in the interface.

 

MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User: []

 

What I'm confused by(take warning here, I'm a completely self-taught novice and struggling) is that the docs say that mixed dml errors occur because a single method is trying to manipulate two different sObjects, and that the solution is to have the two dml statements in two different methods one of which is tagged with @future. However, I am only trying to run DML on the Contact object, so what's the deal?

 

BTW, I'm totally open to people making suggestions on how to make this code more efficient, elegant etc.

 

 

Thanks!

 

 

trigger userTrigger on User (after insert, after update) {

	List<Contact> newCons = new List<Contact>();
	List<Contact> exCons = new List<Contact>();
	
	if(trigger.isInsert) {
		for(User newU : trigger.new) {
			Contact theCon = new Contact();
			theCon.FirstName = newU.FirstName;
			theCon.LastName = newU.LastName;
			theCon.Email = newU.Email;
			theCon.Department =newU.Department__c;
			theCon.Unit__c = newU.Unit__c;
			theCon.StartDate__c = newU.DateofHire__c;
			theCon.EndDate__c = newU.TerminationDate__c;
			theCon.Title = newU.Title;
			theCon.Phone = newU.Phone;
			theCon.AccountId = '001Q000000G7LHh';
			
			newCons.Add(theCon);
			
		}		
	}
	
	insert newCons;
	
	if(trigger.isUpdate) {
		List<Contact> existingCons = [select ID, FirstName, LastName, Email, Department, Unit__c, StartDate__c, EndDate__c, Title, Phone from Contact where Id IN :trigger.newMap.keySet()];
		for(Contact existingCon : existingCons) {
			if(existingCon.FirstName != trigger.newMap.get(existingCon.Id).FirstName) {
				existingCon.FirstName = trigger.newMap.get(existingCon.Id).FirstName;
			}
			if(existingCon.LastName != trigger.newMap.get(existingCon.Id).LastName) {
				existingCon.LastName = trigger.newMap.get(existingCon.Id).LastName;
			}
			if(existingCon.Email != trigger.newMap.get(existingCon.Id).Email) {
				existingCon.Email = trigger.newMap.get(existingCon.Id).Email;
			}
			if(existingCon.Department != trigger.newMap.get(existingCon.Id).Department__c) {
				existingCon.Department = trigger.newMap.get(existingCon.Id).Department__c;
			}
			if(existingCon.Unit__c != trigger.newMap.get(existingCon.Id).Unit__c) {
				existingCon.Unit__c = trigger.newMap.get(existingCon.Id).Unit__c;
			}
			if(existingCon.StartDate__c != trigger.newMap.get(existingCon.Id).DateofHire__c) {
				existingCon.StartDate__c = trigger.newMap.get(existingCon.Id).DateofHire__c;
			}
			if(existingCon.EndDate__c != trigger.newMap.get(existingCon.Id).TerminationDate__c) {
				existingCon.EndDate__c = trigger.newMap.get(existingCon.Id).TerminationDate__c;
			}
			if(existingCon.Title != trigger.newMap.get(existingCon.Id).Title) {
				existingCon.Title = trigger.newMap.get(existingCon.Id).Title;				
			}
			if(existingCon.phone != trigger.newMap.get(existingCon.Id).phone) {
				existingCon.phone = trigger.newMap.get(existingCon.Id).phone;
			}
			
			//newCons.add(existingCon);
		}
	}
	
	update exCons;
}

 

 

Hello Everyone,

 

Does anyone know if its possible to bring the translated value of a Picklist field in a Text Formula Field.

 

I currently have a status picklist field in Object A. Object B is a detail of Object A and I need to display the value of the status field in Object B.

 

I need to support multiple languages, however, when using translations the picklist label translates perfectly at the Object A level but the child records of Object B display the original value.

 

I guess formula fields always retrieve the master labels, is there anyway to get around this in order to get the translated value?

 

Thanks in advance!

I am trying to figure out how to test fields (included within a apex:repeat) to see if they are blank, or null, and if so display some alternate text (Ex: No records to display) in the table instead of a blank table.  Example code snippet below:

 

 

<apex:repeat var="auditList" value="{!relatedTo.Site_Audit__r}">
   <tr>
    <td>
	<apex:outputField value="{!auditList.Audit_Type__c}" />
    </td>
    <td>
       	<apex:outputField value="{!auditList.Delivery_Date__c}" />
    </td>
    <td>
	<apex:outputField value="{!auditList.Review_Date__c}" />
    </td>
   </tr>
</apex:repeat>

 

Thanks for any help or suggestions! 

 

Let's say that one entry of a picklist is defined in the Translation Workbench as follows:

Master value: Hi
Spanish value:Hola
French value: Bonjour

How can I use the metadata API to get the master value from a translated value in a picklist ??
For example: If my only input is "Bonjour" how can I query the Translation Workbench to get "Hi"???

Any idea?
Thanks!

Hi everyone,

 

I started to get the following error message today, everything was working fine and now I can't deploy my classes because the test units fail due to some incorrect signature in the setCurrentPageReference method inside the Test class.

 

I'm getting the following error message:

 

Save error: Method does not exist or incorrect signature: Test.setCurrentPageReference(System.PageReference)

 

Any ideas on what's happening? Can this be related to the Spring '10 upgrade? It's frustrating that this kind of things happen when you're ready to deploy your stuff to production.. 

 

 

 

 

 

 

Hello everyone, I've recieved nothing but great feedback from the autocomplete component I posted previously here in the discussion boards. So here's something else I would like to share with you.

 

Apex Object Merge Class

 

This apex class allows merge operations on a any custom object, please feel free to read more about it here:

 

http://jonathanrm.com/2010/02/force-com-apex-mergereplace-class/

Message Edited by jonathan rico on 02-07-2010 01:54 PM

Hello everyone, I'm trying to override the "Go to list (x)+" link that displays in related list so that It points to a VisualForce page.

 

Overriding the List View for the object in the setup section took care of this, but in order to override the List View I must use a page that is linked to a StandardSetController (using recordSetVar) in order to have it as an available option for override.

 

Everything went fine untill that point.. but 

 

When displaying the records from the  standardset controller I get the list of All of the records and not only the ones from the related list i'm coming from.

 

I supposed this was because there was no way for my VF page to know which are the selected records, or something similar.. so I decided that then I should build my custom related list, but then I noticed that my VF page only recieves a rlid parameter with what I suppose is the id of the child relationship from the parent object.

 

However I don't have the parent Id anymore in the new page and I need this to create my custom set controller in order to get the correct set of records.

What's weird is that if I hover the "Go to list (x)" link I see that the url contains the same rlid parameter and the parent Id, but I'm not sure why the parent Id is removed when overriding the link with visualforce.

 

What would be ideal is that overriding a list view takes care of all of this, and that it knows that it should only display records from the parent object from which i'm coming from. Maybe this is possible and I'm doing something wrong, if this is the case let me know and I'll post my code. 

 

If this is working as designed, then I should build my custom related list but I need to find a way of getting the parent's id in order to limit the set of records.

 

Please let me know if anyone else has bumped into this. If this is working as designed, then what is the real purpose of overriding a List for an Object?

 

Thanks in advance!

Message Edited by jonathan rico on 02-03-2010 02:40 PM
Hello everyone, just wanted to share with the community this custom component I made and give something back for the help I've received. :smileyhappy:

The purpose of the component is to enable autocomplete in lookup fields. I used the autocomplete js created by Jim Roos:
(http://www.jimroos.com/2007/05/ajax-autocomplete.html) but made some modifications to it so that it could interact with an Apex controller among some other things...

So my idea was that if you were making a VF page that had an inputfield that was related to a lookupfield you would just insert this autocomplete component to that inputfield. Something like this:

Code:
           <apex:inputField value="{!Contact.accountid}" id="accname" styleClass="cField">
<c:autocomplete ObjectName="Accounts" InputId="{!$Component.accname}" AutoCompleteId="accACid" ClassName="autocomplete300"/>
</apex:inputField>

The component has 4 parameters:

The name of the object or custom object that the inputfield relates to (new objects must be added inside the apex classes since i had some problems constructing a dynamic query).
The InputId which is used to relate the component to the input field
The id for the Component
A classname parameter that basically just defines the width of the suggestions menu.

Here's a screenshot of how it looks like in action:




Here's a link to the file containing the required files:

AutoCompleteComponent



Jonathan.


Message Edited by jonathan rico on 08-16-2008 01:55 PM

Message Edited by jonathan rico on 08-17-2008 09:04 AM
Message Edited by jonathan rico on 01-02-2010 05:01 PM