• pierrefrazny.ax358
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 23
    Replies

I developped a trigger which creates a new record (object A) when a SF event record is inserted. It works well when a single event is created but does not when the user creates events that are recurring. It the event has 3 recurring events, then I get 4 records A.

 

Is there anything special with the ways the recurring events are created in SF? Any idea?

 

Here is my code:

 

 

trigger CreateSchoolActivity on Event (before insert) {
	if(Trigger.IsInsert || Trigger.IsUpdate){
        List<School_Activity__c> schoolactivityList = new List<School_Activity__c>();
        List<Event> EventList = new List<Event>();
        
       	recordtype rt = [Select  r.Id, r.SobjectType, r.Name From RecordType r where sobjecttype ='Event' and Name = 'School Appointment' limit 1];
		Id EventRTid = rt.Id;
    	for (Event e : Trigger.new) {
           if (Trigger.isInsert && e.RecordTypeId == EventRTid) {
        	  School_Activity__c sa; 
              sa = new School_Activity__c(Activity_Subject__c = e.Subject,Status__c=e.Status__c, Start_Date__c =e.StartDateTime, 
              		End_Date__c=e.EndDateTime, Related_Assignment__c=e.WhatId);
              schoolactivityList.add(sa);
              EventList.add(e);
            }
        }
        
        List<String> ids = new List<String>();
        if (schoolactivityList.size() > 0) {
            Database.SaveResult[] result = Database.Insert(schoolactivityList, false);
            for (Database.SaveResult sr : result){
                ids.add(sr.Id);
            }
        }
        if (ids.size() > 0) {
            for (Integer i=0; i<ids.size(); i++) {
                Event e = EventList.get(i); 
                if (ids.get(i) != null) {
                    e.School_Activity_ID__c = ids.get(i);
                }
            }
        }    
    }
}

 

 

Thanks for your help!

Pierre

Hi,

 

I would like to set a default value for the Start Time and End Time when the user clicks New Event. I created a custom button with the following URL but the syntax I am used in the past for setting default values does not seem to work for this particular field (Start Time is not populated as expected).

Here is the URL:

/00U/e&retURL=%2F{!Assignment__c.Id}&cancelURL=%2F{!Assignment__c.Id}&what_id={!Assignment__c.Id}&&StartDateTime_time="8:00 AM"&EndDateTime_time="4:00 PM"

 

I would appreciate any clues.

Thanks

Pierre

Hi

Is there an easy way to reproduce the default Salesforce Help & Training look & Feel in a Visual Force page?

Thanks!

Pierre

Hi,

When  a user clicks on a tab, I would like the user to a specific URL (a SF view). I understand that I can create a VisualForce page and then redirect the tab to it but I don't know what the VF code to use.  Could someone help?

Thanks

Pierre

I have created a formula field with the following code:

HYPERLINK(Id,"View" ,"_self")

It basically displays a link and when the user clicks on the link it goes to the record. I have this field displayed on a related list. This works great in the standard related list but not when hovering on the related list links at the top of the records. 

 

Any idea?

 

Thanks

 

I wrote a method which is called by a trigger. This method sums all records matching a
specific criteria and update a field on a parent object. 
I have to write several methods which should behave the same way except that the criteria is different adn the field
on the parent object to update is also different.

Is it possible in Apex to pass the name of a field as a parameter of

a method?

 

Hello

I wrote a method which is called by a trigger. This method sums all records matching aspecific criteria and update a field on a parent object. I have to write several methods which should behave the same way except that the criteria is different and the field on the parent object to update is also different.
Is it possible in Apex to pass the name of a field as a parameter of a method? And then use this parameter in a DML and SOQL statements?

Thanks.

Pierre

Hello,

I wrote a class which caculates the number of instance of  a custom object called Volunteer_Registration__c to Contact. This class is called by a trigger on Volunteer_Registration__c (after detele, after insert). It works great except for one scenario: when I delete the last Volunteer Registration record, I expect the the field  'of_Volunteer_Visit__c' to be reset to zero or at least NULL but this does not work. Basically it looks like in this specific scenario the for loop is not executed.

Any idea how I could modify my code to accomodate this scenario?

 

public with sharing class RollupContactInformation {

	public static void DoIndVisit(Set<ID> contIDs) {
                
    	Contact[] updateContacts = new Contact[]{};
        
        Map<ID, Contact> contacts = new Map<ID, Contact>([SELECT Id FROM Contact WHERE Id in: ContIDs ]);
                        
        //Loop over the aggregate result set
	for (AggregateResult ar : [select Contact__c, COUNT(Id)numVisits From Volunteer_Registration__c Where Contact__c in: ContIDs and Status__c = 'Completed' AND Inquiry_Type__c = 'Individual' group by Contact__c ]) 
		{	
			
		Contact thisContact = new Contact(Id=String.valueOf(ar.get('Contact__c')));
		thisContact.of_Volunteer_Visit__c = Integer.valueOf(ar.get('numVisits')); 
				
		//Add this new account to the list of account objects
		updateContacts.add(thisContact);
		}

		//Update the account object.
		if(updateContacts.size()>0) {update updateContacts;}	
        }
}

 Thanks   a lot.

Pierre

I have a lookup to Contact on an record o and would like to retrieve the value of a field on contact. This syntax does not seem to work:

o.Contact__r.number__c

Do I really have to run a SOQL query the information? 

Thanks

Pierre 

Is it possible to use a trigger to automate the creation of Campaign Member Status? For example, when a campaign of certain type is created, I would like to automatically add 'Show', 'No show' i nthe list of Campaign Member Status. Is it possible?

Thanks

Pierre 

I have 2 object:

- Contact

- Affiliation__c. There is a master-detail field called Contact__c on Affiliation which related Contact and Affiliation. (the Child Relationship Name is Affiliations)

 

 

Contact[] conts = new List<Contact>(); conts = [select Id, (select Id from Affiliations__r where Type = 'Volunteer') from Contact where ID in :contIDs ];

 

I get the following error:" Didn't understand relationship 'Affiliations__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. "

 

Any ideas?

Thanks

Pierre

 

I have 4 unmanaged packages. The last package relies on fields included in the first 3 packages.

1- Is it a good practice? (should I simply one package)

2- When I try to create the 4th package, all dependents fields (already part of other packages) are automatically added. I tried to create the 4th package in a separate instance (different than the one used to create the first 3 packages) but the same thing happen. 

 

Any ideas what i am missing?

 

Thanks

Pierre

 

Hello,
I have the following lines of code to get a RecordTypeId.

Id CampaignTypeId = [Select Id from RecordType where Name = 'Attendance Campaign' and SObjectType = 'Campaign'].Id;Contact[] conts = new List<Contact>();conts = [select Id, Last_Campaign_Date__c ,(select Campaign.StartDate from CampaignMembers where HasResponded = TRUE AND Campaign.RecordTypeId = CampaignTypeId order by Campaign.StartDate Desc) from Contact where ID in :contIDs ];

 


I get the following error: 
Save error: unexpected token: 'CampaignTypeId'

If I hardcode the record type id ( ex: Campaign.RecordTypeId = '01270000000AfEX'), I do *not* get the error

Any clue?

Thanks a lot.

Hello,

I have a button which executes some javascript. I need to expose this function via the api. 

Could I call the javascript in a apex? and then could I call the apex function via the api?

Thanks 

Hello,

I am writting a trigger to rollup a field (Type) from the Opportunity object on Account. I get the error "Didn't understand relationship 'Opportunities' error". I am out of ideas. Any clue?

 

 

trigger UpdateMembershipType on Opportunity (after delete, after insert, after update) { set<ID> orgIDs = new Set<ID>(); if(Trigger.isInsert) { for(Opportunity o : System.Trigger.new){ orgIDs.add(o.AccountId); } Organization[] orgs = new List<Organization>(); orgs = [select Id, (select Type, RecordType.Name from Opportunities where IsWon = TRUE order by CloseDate Desc limit 1 ) from Organization where ID in :orgIDs ]; Opportunity[] os = new List<Opportunity>(); Map<Id, Opportunity[]> orgopp = new Map<Id, Opportunity[]>(); for (Organization eachOrg: orgs){ orgopp.put(eachOrg.Id, eachOrg.Opportunities); } Organization[] updatedOrganizations = new List<Organization>(); Opportunity[] opps = new List<Opportunity>(); for (Organization o : orgs ){ opps=orgopp.get(o.Id); for(Opportunity opty : opps) { o.Type__c=opty.Type; } updatedOrganizations.add(o); } if(updatedOrganizations.size()>0) {update updatedOrganizations;}}

 

 Thanks!

Pierre 

 

 

We are a small SF consulting partner and we are looking for a consultant to help us primarly with data migration projects. We would like to build a long term partnership. There will be other opportunities to work on other project aspects (requirements, design...).

 

The most important qualities in the person we are looking for:

1. On time

2. Serious 

3. Independant

 

 

Our most immediate need is a migration from Goldmine.

Please contact us at info@frazny.com if you are interested and have experience with migration from Goldmine.

Thanks.

Pierre 

My end goal is to populate a Date/Time field. 

My users would rather use 2 fields to enter date and time rather than the SF Date/Time field. I created a date field (Activity_Date) and text field (Activity_Time). I added a validation rule to make sure Activity_Time would be properly formatted (ex: 8:30 or 16:15). Now I realize that the SF Date/Time field is very convenient in order to sort records. Is there a formula I could use to recombine these 2 fields to populate a Date/Time field?

Thanks!

Pierre 

Hello,

I would like to automate the creation of an Account when a Contact is created and the Account Name is left blank.  Do I need Visual Force for this or is an Apex trigger sufficient? Could someone put me in the right direction?

Thanks

Pierre 

Hello,
I am trying to retrieve the detail records at the same time as the master record. I added a custom field lookup on Opportunity to Account (Contact__c).
 I get this error in Eclipse for the last line of code: "The configuration of your org has changed, please reload the page. Missing dependent object: Field: Opportunity.ContactId".
Could anybody help?
The business scenario that I have is totry to get is the latest Membership_End_Date__c for all Opportunities related to a given Contact.
 Thanks!

trigger UpdateIndividualMemberEndDate on Opportunity (after insert) { set<ID> contIDs = new Set<ID>(); if(Trigger.isInsert) { for(Opportunity o : System.Trigger.new){ contIDs.add(o.Contact__c); } Contact[] conts = new List<Contact>(); conts = [select Id, (select Membership_End_Date__c from Opportunities Order by Membership_End_Date__c desc) from Contact where ID in :contIDs]; Map<Id, Opportunity[]> contopp = new Map<Id, Opportunity[]>(); for (Contact eachCont: conts) { contopp.put(eachCont.Id, eachCont.Opportunities);} } }

 

 

I have been working on this trigger for a day now so I wondering if anybody could give me ideas. I have 2 objects: Account and Gig__c. I need to calculate the sum of Total_Estimated_Hours__c (on Gig__c) and copy it to of_Hours__c (on Account). The trigger works but I woulk to understand how I can move the second SELECT out of the loop. Here is the portion of the code in question:

 

 

trigger UpdateTotalHours1 on Gig__c (after delete, after insert, after update) { set<ID> acctIDs = new Set<ID>(); if(Trigger.isInsert) { for(Gig__c g : System.Trigger.new){ acctIDs.add(g.Customer__c); } Account[] accts = new List<Account>(); //get the list of acccount accts = [select Id, of_Hours__c from Account where ID in :acctIDs]; Account[] updatedAccounts = new List<Account>(); for (Account a : accts ){ Double SumOfHours = 0; for (Gig__c gig : [SELECT Id, Total_Estimated_Hours__c from Gig__c where Customer__c=:a.Id]) { SumOfHours += gig.Total_Estimated_Hours__c; } a.of_Hours__c = SumOfHours; updatedAccounts.add(a); } update updatedAccounts; }}

 

 

 

 

 

Thanks.

 

Pierre 

 

 


 

Message Edited by pierrefrazny on 04-16-2009 03:18 PM

Hi,

 

I would like to set a default value for the Start Time and End Time when the user clicks New Event. I created a custom button with the following URL but the syntax I am used in the past for setting default values does not seem to work for this particular field (Start Time is not populated as expected).

Here is the URL:

/00U/e&retURL=%2F{!Assignment__c.Id}&cancelURL=%2F{!Assignment__c.Id}&what_id={!Assignment__c.Id}&&StartDateTime_time="8:00 AM"&EndDateTime_time="4:00 PM"

 

I would appreciate any clues.

Thanks

Pierre

Hi,

When  a user clicks on a tab, I would like the user to a specific URL (a SF view). I understand that I can create a VisualForce page and then redirect the tab to it but I don't know what the VF code to use.  Could someone help?

Thanks

Pierre

I have created a formula field with the following code:

HYPERLINK(Id,"View" ,"_self")

It basically displays a link and when the user clicks on the link it goes to the record. I have this field displayed on a related list. This works great in the standard related list but not when hovering on the related list links at the top of the records. 

 

Any idea?

 

Thanks

Hello,

I get the following error at runtime when a given contact has  more than 499 related Cases:

Error: Invalid Data. 
Review all error messages below to correct your data.
common.apex.runtime.impl.TriggerExecutionException: Apex trigger TotalsUpdate caused an unexpected exception, contact your administrator: TotalsUpdate: execution of AfterUpdate caused by: System.Exception: Too many query rows: 1002: Trigger.TotalsUpdate: line 44, column 11
 

 

Line 44 corresponds to this:

 

conts = [select Id, Last__Date__c, First__Date__c, Vol_Hours__c, Num_of_shift__c, (select of_Hours__c, Activity_Date__c from Cases order by Activity_Date__c Desc) from Contact where ID in :contIDs ];

 

Is this an issue with the governor limit?

 

If this is the case, is there a way to avoid the limit?

 

Thanks a lot.

 

Pierre

 

Here is the full trigger: 

trigger TotalsUpdate on Case (after delete, after insert, after update) { set<ID> contIDs = new Set<ID>(); if(Trigger.isInsert) { for(Case c : System.Trigger.new){ if (c.of_Hours__c <> NULL) {contIDs.add(c.ContactId);} } Contact[] conts = new List<Contact>(); conts = [select Id, Last__Date__c, First__Date__c, Vol_Hours__c, Num_of_shift__c, (select of_Hours__c, Activity_Date__c from Cases order by Activity_Date__c Desc) from Contact where ID in :contIDs ]; Case[] ca = new List<Case>(); Map<Id, Case[]> contcase = new Map<Id, Case[]>(); for (Contact eachCont: conts){ contcase.put(eachCont.Id, eachCont.Cases); } Contact[] updatedContacts = new List<Contact>(); Case[] cas = new List<Case>(); for (Contact c : conts ){ cas=contcase.get(c.Id); c.Last__Date__c = cas[0].Activity_Date__c; c.First__Date__c = cas[cas.size()-1].Activity_Date__c; Double SumOfHours = 0; Double NumOfShift = 0; for(Case cse : cas) { SumOfHours += cse.of_Hours__c; NumOfShift = NumOfShift + 1; } c.Vol_Hours__c = SumOfHours; c.Num_of_shift__c = NumOfShift; updatedContacts.add(c); } if (updatedContacts.size()>0) {update updatedContacts;} } if(Trigger.isDelete || Trigger.isUpdate) { for(Case c : System.Trigger.old){ if (c.of_Hours__c <> NULL) {contIDs.add(c.ContactId);} } Contact[] conts = new List<Contact>(); conts = [select Id, Last__Date__c, First__Date__c, Vol_Hours__c, Num_of_shift__c, (select of_Hours__c, Activity_Date__c from Cases order by Activity_Date__c Desc) from Contact where ID in :contIDs ]; Case[] ca = new List<Case>(); Map<Id, Case[]> contcase = new Map<Id, Case[]>(); for (Contact eachCont: conts){ contcase.put(eachCont.Id, eachCont.Cases); } Contact[] updatedContacts = new List<Contact>(); Case[] cas = new List<Case>(); for (Contact c : conts ){ cas=contcase.get(c.Id); Double SumOfHours = 0; Double NumOfShift = 0; c.Last__Date__c = NULL; c.First__Date__c = NULL; if(cas.size()>0){ c.Last__Date__c = cas[0].Activity_Date__c; c.First__Date__c = cas[cas.size()-1].Activity_Date__c; for(Case cse : cas) { SumOfHours += cse.of_Hours__c; NumOfShift = NumOfShift + 1; } } c.Vol_Hours__c = SumOfHours; c.Num_of_shift__c = NumOfShift; updatedContacts.add(c); } if (updatedContacts.size()>0) {update updatedContacts;} } }

 

 

   
  • March 04, 2010
  • Like
  • 0

I have a lookup to Contact on an record o and would like to retrieve the value of a field on contact. This syntax does not seem to work:

o.Contact__r.number__c

Do I really have to run a SOQL query the information? 

Thanks

Pierre 

Is it possible to use a trigger to automate the creation of Campaign Member Status? For example, when a campaign of certain type is created, I would like to automatically add 'Show', 'No show' i nthe list of Campaign Member Status. Is it possible?

Thanks

Pierre 

I have 2 object:

- Contact

- Affiliation__c. There is a master-detail field called Contact__c on Affiliation which related Contact and Affiliation. (the Child Relationship Name is Affiliations)

 

 

Contact[] conts = new List<Contact>(); conts = [select Id, (select Id from Affiliations__r where Type = 'Volunteer') from Contact where ID in :contIDs ];

 

I get the following error:" Didn't understand relationship 'Affiliations__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. "

 

Any ideas?

Thanks

Pierre

 

Hello,
I have the following lines of code to get a RecordTypeId.

Id CampaignTypeId = [Select Id from RecordType where Name = 'Attendance Campaign' and SObjectType = 'Campaign'].Id;Contact[] conts = new List<Contact>();conts = [select Id, Last_Campaign_Date__c ,(select Campaign.StartDate from CampaignMembers where HasResponded = TRUE AND Campaign.RecordTypeId = CampaignTypeId order by Campaign.StartDate Desc) from Contact where ID in :contIDs ];

 


I get the following error: 
Save error: unexpected token: 'CampaignTypeId'

If I hardcode the record type id ( ex: Campaign.RecordTypeId = '01270000000AfEX'), I do *not* get the error

Any clue?

Thanks a lot.

Hello,

I am writting a trigger to rollup a field (Type) from the Opportunity object on Account. I get the error "Didn't understand relationship 'Opportunities' error". I am out of ideas. Any clue?

 

 

trigger UpdateMembershipType on Opportunity (after delete, after insert, after update) { set<ID> orgIDs = new Set<ID>(); if(Trigger.isInsert) { for(Opportunity o : System.Trigger.new){ orgIDs.add(o.AccountId); } Organization[] orgs = new List<Organization>(); orgs = [select Id, (select Type, RecordType.Name from Opportunities where IsWon = TRUE order by CloseDate Desc limit 1 ) from Organization where ID in :orgIDs ]; Opportunity[] os = new List<Opportunity>(); Map<Id, Opportunity[]> orgopp = new Map<Id, Opportunity[]>(); for (Organization eachOrg: orgs){ orgopp.put(eachOrg.Id, eachOrg.Opportunities); } Organization[] updatedOrganizations = new List<Organization>(); Opportunity[] opps = new List<Opportunity>(); for (Organization o : orgs ){ opps=orgopp.get(o.Id); for(Opportunity opty : opps) { o.Type__c=opty.Type; } updatedOrganizations.add(o); } if(updatedOrganizations.size()>0) {update updatedOrganizations;}}

 

 Thanks!

Pierre 

 

 

My end goal is to populate a Date/Time field. 

My users would rather use 2 fields to enter date and time rather than the SF Date/Time field. I created a date field (Activity_Date) and text field (Activity_Time). I added a validation rule to make sure Activity_Time would be properly formatted (ex: 8:30 or 16:15). Now I realize that the SF Date/Time field is very convenient in order to sort records. Is there a formula I could use to recombine these 2 fields to populate a Date/Time field?

Thanks!

Pierre 

Hello,

I would like to automate the creation of an Account when a Contact is created and the Account Name is left blank.  Do I need Visual Force for this or is an Apex trigger sufficient? Could someone put me in the right direction?

Thanks

Pierre 

Hello,
I am trying to retrieve the detail records at the same time as the master record. I added a custom field lookup on Opportunity to Account (Contact__c).
 I get this error in Eclipse for the last line of code: "The configuration of your org has changed, please reload the page. Missing dependent object: Field: Opportunity.ContactId".
Could anybody help?
The business scenario that I have is totry to get is the latest Membership_End_Date__c for all Opportunities related to a given Contact.
 Thanks!

trigger UpdateIndividualMemberEndDate on Opportunity (after insert) { set<ID> contIDs = new Set<ID>(); if(Trigger.isInsert) { for(Opportunity o : System.Trigger.new){ contIDs.add(o.Contact__c); } Contact[] conts = new List<Contact>(); conts = [select Id, (select Membership_End_Date__c from Opportunities Order by Membership_End_Date__c desc) from Contact where ID in :contIDs]; Map<Id, Opportunity[]> contopp = new Map<Id, Opportunity[]>(); for (Contact eachCont: conts) { contopp.put(eachCont.Id, eachCont.Opportunities);} } }