0

I was wondering if there is a way to access the User information page to obtain the Country and Title from that page, for people that are invited to an Event.

So, I created an Event and invited a number of USER/s. My intention is to access the USER's info pages of those that are part of the "Invite Other" section.

Is this something possible using a formula function?

Thanks on advanced!


Hello guy,

I have a number formula, (total time) to obtain StartDate and EndDate duration in hours for every single event. Using the output of that formula I make some calculations.

First I access the event's owner user Country field. I do this to assign him a currency with something like this:

CASE($User.Country, "AUS", "Australian dollar", "US", "United States dollar", "No country assigned to user")

We have an hourly rate for some users and those rates are assign using this type of formulas, field name Hourly Rate :

IF(($User.Country = "CA" ),00.00, IF(($User.Country = "AUS" ),00.00, null))

All this is the output of a field call Activity Total Amount. A simple operation "Total Time * Hourly Rate"

So the request now is to add to the Total Amount formula field the rates for all users that are invited to an event.

So if an event takes one hour I need that the Activity Total Amount reflects amounts from the user that are invited together with the acctivity.owner.

Does this explains better what I'm looking for?

  • Could you include a screenshot of where you want the fields to appear? That would help in getting your requirement clear. – Guy May 9 '14 at 9:30
  • Note that $User is always the current, running user. The schema behind what you are doing is Event -> EventRelation <- (User, Contact, or Lead) [polymorphic] – cropredy May 9 '14 at 19:49
  • Is this by any chance an email template? Or are you asking about Event's page layout? A report? – eyescream May 9 '14 at 23:32
  • Is on the Event page layout eyescream. crop, are you saying that i is possible to reach the other users that are invited to an event by using the EvenRelation? I thought that this was only for contacts and leads. My first idea was to look into the possibility of using formula functions for this but I think that I will need to write a trigger on the Event object to accomplish this. I'm still worried about the ability to access Users, not contacts or leads from the apex trigger. – Carlos Naranjo May 10 '14 at 16:13
0

Thanks guys,

I have solved now. I need to write a trigger to accomplish what I want. In case anyone needs to test this for future code here is a anonymous block of code that you can use for testing from your IDE or from a Developer Console:

 //The whoRelations list contains users that accepted an invitation for an event

 List<EventRelation> whoRelations = [SELECT Id, Relation.Name, Status FROM EventRelation WHERE
 EventId = 'YourEventID' AND Status = 'Accepted'];

// If there is at least one user you can see his/her 
//name and Id by using Relation.Name and Relation.Id

 System.debug(whoRelations[0].Relation.Name);
 System.debug(whoRelations[0].Relation.Id);

//I created an Id list to pass the ids in whoRelations list to the new userId list.
List<Id> userId = new List<Id>();

//We pass all ids to our userId list now

for(Integer i=0; i<whoRelations.size(); i++){

  userId.add(whoRelations[i].Relationid);

}

//Now we just use a SOQL on the User object for users on our userId list.
//From here we can now access all user's details fields. 

System.debug(userId.size());

List<User> finalUsers = [SELECT Id, Name, Title, Country FROM USER WHERE Id IN :userId];

//In my test I had 2 users in my finalUsers list, to see the results I used this.

if(!finalUsers.IsEmpty()){

System.debug(finalUsers[0].Id);
System.debug(finalUsers[0].Country);
System.debug(finalUsers[1].Id);
System.debug(finalUsers[1].Country);
}

By using this I can now start building a trigger that will take the rest of my logic into the Event's page layout, allowing me to use data that are part on the User object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.