• ehartye
  • NEWBIE
  • 75 Points
  • Member since 2009

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

Ok so here is the scenario.  We have an application object which contains information about several entities: 3 contacts and 3 custom objects we have called involvements, one associated with each person.  Inside of the involvement object we have a drop down list with several options and depending on the option you have selected different fields are displayed and different validation rules are applied.  I am not sure if that is what is causing me this issue, but anytime I attempt to insert a new application object I get this error being thrown:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger parseStudentApplication caused an unexpected exception, contact your administrator: parseStudentApplication: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Contact]: [Contact]: Class.StudentApplicationParser.Parse: line 182, column 9

 

The following is my trigger:

trigger parseStudentApplication on Application_For_Admission__c(after insert) {
    List<Application_For_Admission__c> studentApps = Trigger.new;
    {
        StudentApplicationParser sap = new StudentApplicationParser();
        sap.Parse(studentApps);
    } 
}

 

Here is the class that process the trigger:

public with sharing class StudentApplicationParser {
    public void Parse(List<Application_For_Admission__c> sas)
    {
        List<Contact> contacts = new List<Contact>();
        List<Account> accounts = new List<Account>();
        List<npe4__Relationship__c> relationships = new List<npe4__Relationship__c>();
        List<Involvement__c> involvements = new List<Involvement__c>();
        List<Semester__c> semesters = new List<Semester__c>();
        List<School__c> schools = new List<School__c>();
        for(Application_For_Admission__c sa : sas)
        {
            Contact student = new Contact();
            Account studentAcct = new Account();
            Contact mother = new Contact();
            Account motherAcct = new Account();
            Contact father = new Contact();
            Account fatherAcct = new Account();
            npe4__Relationship__c relToMother = new npe4__Relationship__c();
            npe4__Relationship__c relToFather = new npe4__Relationship__c();
            Involvement__c studentInvolvement = new Involvement__c();
            Involvement__c motherInvolvement = new Involvement__c();
            Involvement__c fatherInvolvement = new Involvement__c();
            student.FirstName = sa.First_Name__c;
            student.LastName = sa.Last_Name__c;
            student.Birthdate = sa.Birthdate__c;
            student.MailingStreet = sa.Student_Address__c;
            student.MailingCity = sa.City__c;
            student.MailingState = sa.State__c;
            student.MailingPostalCode = sa.Zip__c;
            student.OtherPhone = sa.Phone__c;
            student.npe01__PreferredPhone__c = 'Other';
            student.npe01__HomeEmail__c = sa.Student_Email_Address__c;
            student.npe01__Preferred_Email__c = 'Home';
            System.debug('Set all student fields');
            mother.FirstName = sa.Mother_First_Name__c;
            mother.LastName = sa.Mother_Last_Name__c;
            mother.npe01__HomeEmail__c = sa.Mother_Email_Address__c;
            mother.npe01__Preferred_Email__c = 'Home';
            mother.npe01__WorkPhone__c = sa.Mothers_Work_Phone__c;
            mother.OtherPhone = sa.Mothers_Home_Phone__c;
            mother.npe01__PreferredPhone__c = sa.Mother_Preferred_Phone__c;
            mother.npe01__WorkPhone__c = sa.Mothers_Work_Phone__c;
            mother.MobilePhone = sa.Mothers_Cell_Phone__c;
            if(sa.Mothers_Address__c == null)
            {   
                mother.MailingStreet = sa.Student_Address__c;
                mother.MailingCity = sa.City__c;
                mother.MailingState = sa.State__c;
                mother.MailingPostalCode = sa.Zip__c;
                System.debug('Set all mother fields with same address as child');
            }
            else
            {
                mother.MailingStreet = sa.Mothers_Address__c;
                mother.MailingCity = sa.Mothers_City__c;
                mother.MailingState = sa.Mothers_State__c;
                mother.MailingPostalCode = sa.Mothers_Zip__c;
                System.debug('Set all mother fields with own address');
            }
            father.FirstName = sa.Father_First_Name__c;
            father.LastName = sa.Father_Last_Name__c;
            father.npe01__HomeEmail__c = sa.Father_Email_Address__c;
            father.npe01__Preferred_Email__c = 'Home';
            father.npe01__WorkPhone__c = sa.Fathers_Work_Phone__c;
            father.OtherPhone = sa.Fathers_Home_Phone__c;
            father.npe01__PreferredPhone__c = sa.Father_Preferred_Phone__c;
            father.npe01__WorkPhone__c = sa.Fathers_Work_Phone__c;
            father.MobilePhone = sa.Fathers_Cell_Phone__c;
            if(sa.Fathers_Address__c == null)
            {
                father.MailingStreet = sa.Student_Address__c;
                father.MailingCity = sa.City__c;
                father.MailingState = sa.State__c;
                father.MailingPostalCode = sa.Zip__c;
                System.debug('Set all father fields with same address as child');
            }
            else
            {
                father.MailingStreet = sa.Fathers_Address__c;
                father.MailingCity = sa.Fathers_City__c;
                father.MailingState = sa.Fathers_State__c;
                father.MailingPostalCode = sa.Fathers_Zip__c;    
                System.debug('Set all father fields with own address');         
            }
            relToMother.npe4__Contact__c = student.Id;
            relToMother.npe4__RelatedContact__c = mother.Id;
            relToMother.npe4__Description__c = 'Parent/Child';      
            relToMother.npe4__Status__c = 'Active'; 
            relToMother.npe4__Type__c = 'Family';
            System.debug('Set relationship to mother');
            relToFather.npe4__Contact__c = student.Id;
            relToFather.npe4__RelatedContact__c = father.Id;
            relToFather.npe4__Description__c = 'Parent/Child';
            relToFather.npe4__Status__c = 'Active';
            relToFather.npe4__Type__c = 'Family';
            System.debug('Set relationship to father');
            //studentInvolvement.Contact__c = student.Id;
            //studentInvolvement.Involvement__r = student.Id;
            studentInvolvement.Involvement_Level__c = 'Student';
            //studentInvolvement.Academic_Semester__c = current.Id;
            studentInvolvement.Grade_Level__c = sa.Grade__c;
            studentInvolvement.Gender__c = sa.Gender__c;
            studentInvolvement.Race__c = sa.Race__c;
            studentInvolvement.Level_Enrolled__c = sa.Enrollment_Level__c;
            studentInvolvement.Date_of_Birth__c = sa.Birthdate__c;
            studentInvolvement.Place_of_Worship__c = sa.Worship_Place__c;
            Semester__c current;
            Integer semCount = [Select Count() From Semester__c a where name = :sa.Academic_Semester__c];
            if(semCount == 0)
            {
               current = new Semester__c(name = sa.Academic_Semester__c);
               semesters.add(current);
            }
            else
            {
                current = [Select Id From Semester__c where name = :sa.Academic_Semester__c];
            }

  • May 28, 2010
  • Like
  • 0

I keep getting Too many SOQL Queries when I thought I wrote a bulk trigger until I did dataloader on update.. to get the porevious records.. Here is my code:

 

trigger bulktriggerfd on Placement__c (before insert,before update,after insert) { 
//Place the dataset in a Map to what is common in both objects 
//What would be the same through out the objects
Map<Id, Placement__c> PLAC = new Map<Id, Placement__c>();
for (Integer i = 0; i < Trigger.new.size(); i++) {
    if (System.Trigger.isInsert) {
        PLAC.put(Trigger.new[i].Participant__c,Trigger.new[i]); 
    }
    else if(System.Trigger.isUpdate){
        PLAC.put(Trigger.old[i].Participant__c,Trigger.new[i]);  
    }
}
//New List view 
List<Contact> updatedconField = new List<Contact>();
List<Placement__c> updatedplacField = new List<Placement__c>();

if(System.Trigger.isUpdate){
for (Contact c : [SELECT id,AccountId FROM Contact WHERE Id in :PLAC.keySet()]) {
        Placement__c parentAccount = PLAC.get(c.id);
        If(parentAccount.End_Date__c==null){
            c.AccountId = parentAccount.School__c;
            c.Current_Placement__c = parentAccount.Id;
            c.Current_Founder__c = parentAccount.Founder__c;
            c.Current_Program_City__c = parentAccount.Program_City__c;   
            c.Current_Role__c  = parentAccount.Role__c;  
            c.Current_Additional_Role_Info__c = parentAccount.Additional_Role_Info__c;
            c.Current_Weeks_Placed_in_Advance__c = parentAccount.Weeks_Placed_in_Advance__c;
            c.Current_Description__c   = parentAccount.Description__c; 
        }  
        if(parentAccount.End_Date__c!=null){
            List<Placement__c> pl = [Select id from Placement__c Where Id in :PLAC.keySet() and End_Date__c=null];
            if(pl.size()>0){
            c.AccountId = pl[0].School__c;
            c.Current_Placement__c = pl[0].Id;
            c.Current_Founder__c = pl[0].Founder__c;
            c.Current_Program_City__c = pl[0].Program_City__c;   
            c.Current_Role__c  = pl[0].Role__c;  
            c.Current_Additional_Role_Info__c = pl[0].Additional_Role_Info__c;
            c.Current_Weeks_Placed_in_Advance__c = pl[0].Weeks_Placed_in_Advance__c;
            c.Current_Description__c   = pl[0].Description__c; 
            }
            if(pl.size()==0){
            c.Current_Placement__c = null;
            c.Current_Program_City__c = null;   
            c.Current_Role__c  = null;  
            c.Current_Additional_Role_Info__c = null;
            c.Current_Weeks_Placed_in_Advance__c = null;
            c.Current_Description__c   = null;
            }
        }     
        System.Debug('parentAccount -  ' + parentAccount);
        
        updatedconField.add(c);
    }
    } 

if(System.Trigger.isInsert){
for (Contact c : [SELECT id,AccountId,Current_Placement__c FROM Contact WHERE Id in :PLAC.keySet()]) {
        Placement__c parentAccount = PLAC.get(c.id);
        If(parentAccount.End_Date__c==null){
            c.AccountId = parentAccount.School__c;
            c.Current_Placement__c = parentAccount.Id;
            c.Current_Founder__c = parentAccount.Founder__c;
            c.Current_Program_City__c = parentAccount.Program_City__c;   
            c.Current_Role__c  = parentAccount.Role__c;  
            c.Current_Additional_Role_Info__c = parentAccount.Additional_Role_Info__c;
            c.Current_Weeks_Placed_in_Advance__c = parentAccount.Weeks_Placed_in_Advance__c;
            c.Current_Description__c   = parentAccount.Description__c;             
            System.Debug('id = ' + parentAccount.Id);
        }
        System.Debug('parentAccountnew -  ' + parentAccount);
        
        updatedconField.add(c);
}
}    
    
    update updatedconField;
}

 

Thanks

 

Is there a good way to filter these out? Here's an example from a Chatter feed component I'm working on: 

 

Here's my controller:

 

 

public with sharing class ChatterObjectFeed {

    public String oID{ get; set; }
    
    public String oType{ get; set; }    
    
    public String feedPost{ get; set; }
    
    public ChatterObjectFeed(){}
    
    public class objFeed{
    	public id createdById {get; set;}
    	public string createdByName {get; set;}
    	public string createdDate {get; set;}
    	public string body {get; set;}
    	public string title {get; set;}
    	public string linkURL {get; set;}
    	public list <FeedTrackedChange> Changes {get; set;}
    	public list <FeedComment> Comments {get; set;}
    	
    	public objFeed()
    	{
    		Changes = new List<FeedTrackedChange>();
    		Comments = new List<FeedComment>();
    	}
    }
    
    

	public list <objFeed> getObjFeed()
	{
		list<objFeed> feed = new list<objFeed>();
		
		string strQuery = 'SELECT Id, Type, CreatedById, CreatedBy.FirstName, CreatedBy.LastName, CreatedDate, ParentId' 
		+ ', FeedPostId, FeedPost.Body, FeedPost.Title, FeedPost.CreatedById, FeedPost.LinkUrl'
		+ ', (SELECT Id, FieldName, OldValue, NewValue FROM FeedTrackedChanges ORDER BY Id DESC)'
	    + ', (SELECT Id, CommentBody, CreatedDate,CreatedById, CreatedBy.FirstName, CreatedBy.LastName FROM FeedComments ORDER BY CreatedDate DESC, ID DESC)'
		+ 'FROM ' + oType + 'Feed WHERE ParentId=\'' + oID + '\' ORDER BY CreatedDate DESC, ID DESC';
		
		for(SObject o : database.query(strQuery))
		{
			objFeed f = new objFeed();
			f.createdById = (string)o.get('CreatedById');
			f.createdByName = (string)o.getSObject('CreatedBy').get('FirstName') + ' ' + (string)o.getSObject('CreatedBy').get('LastName');
			Datetime createdDateDT = (datetime)o.get('CreatedDate');
			f.createdDate = createdDateDT.format();
			
			FeedPost p = (FeedPost)o.getSObject('FeedPost');
			If(p!=Null)
			{
				f.body = p.body;
				f.title = p.Title;
				f.linkURL = p.LinkUrl;
			}
			
			f.Comments = (FeedComment[])o.getSObjects('FeedComments');
			f.Changes = (FeedTrackedChange[])o.getSObjects('FeedTrackedChanges');
			
			feed.add(f);
		}
		
		return feed;
	}
	
}

 

 



 

 

Internal Salesforce.com Query Error

 

An unexpected error has occurred. Your solution provider has been notified. (ComboPack)

 

 

Oddly enough, as an administrator, the page loads fine for me, but no one else. Sadly, I don't get the email this generates, so I can't really do any kind of troubleshooting. Has anyone seen this? Does anyone know how to get the email sent to me rather than ComboPack?

Adding the VF page as an inline object to a standard page layout is not a viable option for my implementation.

 

Does anyone know of an example of someone re-creating the Chatter bar in VF?

Users created with an external .net app we've made aren't getting the email with their login info. How is that supposed to work?

I've tried several approaches to this, and I'm not really happy with any of them. I'm hoping someone here can point me to a best practice example.

 

I have a custom object related list on accounts. On every account, I want to see the total record count of these objects that exist below it in the hierarchy. For example:

 

Child Account 1 of Parent Account 1 has 2 related records, Child Account 2 of Parent Account 1 has 3 related records. The record total field on Parent Account 1 would show 5.

 

If it helps, I've programmatically constrained my account hierarchy to 3 levels. 

Currently, I have the default Case pages overridden. I have users that fall into a few different categories that all need to be able to create or manage cases.

 

1. Internal users in role abc.

2. Internal users in role xyz.

3. 3rd party contractors. 

4. Customer Portal users. 

 

And the list keeps growing, and growing.

 

Currently, the way I deal with this is to use one page as the overriding page, and within the page have code like this:

 

<apex:include pageName="pageNameabc" rendered="{!$user.ProfileId == 'abc123'}">

 

<apex:include pageName="pageNamexyz" rendered="{!$user.ProfileId == 'xyz123'}">

 I am not a fan of this implementation. Hard coding Id's is not ideal, but I've not found a better way to achieve what I need.

 
Message Edited by ehartye on 11-24-2009 08:49 AM

I'm seeing some strange behavior from commandlink on one of my pages. Here's my code:

 

 

<apex:pageBlockTable value="{!results}" var="l" rendered="{!NOT(ISNULL(results))}"><apex:column > <apex:commandLink id="selectLink" action="{!selectSolution}" immediate="true"> <apex:param id="caseSol" name="caseSol" value="{!l.Id}"/> Select </apex:commandLink></apex:column><apex:column headervalue="Solution Title"> <apex:outputLink value="/{!l.Id}" target="_blank" onmouseover="Tip('{!l.solutionNote}', TITLE, '{!l.solutionname}', STICKY, true, CLOSEBTN, true, WIDTH, -800)" onmouseout="UnTip()">{!l.solutionname}</apex:outputLink></apex:column><apex:column value="{!l.Status}"/><apex:column value="{!l.createddate}"/></apex:pageBlockTable>

 The table shows a list of solutions from a search, displayed on a case vf page, all with a select link to apply the solution to the case.

 

My problem is that about 20% of the time, clicking the select link just reloads the page rather than performing the action.

 

I've checked the debug log during these occurances, and the action method isn't even being hit. It's like it just stalls out.

 

Any ideas? 

 

 

  • September 29, 2009
  • Like
  • 0

I have a new case interface I'd like my organization to use by default, but I want my customers in the Portal to continue seeing the old standard page layouts.

 

Is this possible? 

  • September 25, 2009
  • Like
  • 0

This may be common knowledge, but I'm a Java rookie and was pretty pleased with myself when I figured it out :smileytongue: .

 

If you're working with html solutions and need to use SolutionNote somewhere that doesn't support html formatting, the problem is easily solved using regular expressions like this:

 

 

NonHTMLField = SolutionNote.replaceAll('\\<.*?\\>', '');

 

 

Message Edited by ehartye on 08-13-2009 05:57 AM

Those of you familiar with the table structure for Cases and Solutions know that the CaseSolution table is used to allow a many-to-many relationship.

 

I'm trying to trigger apex when the user adds a solution or removes one from the case. The problem is that you can do this without editing the case or the solution. You also cannot trigger on the CaseSolution SObject.

 

Does anyone have a suggestion for triggering on this event? 

Does anyone know how to prevent a user from voting on an Idea based on their profile?

 

I've tried to do this with an Idea trigger, but been unsuccessful because voting on an idea doesn't actually edit it.

 

I realize you can create an entire custom Ideas controller and interface to accomplish this, but I would really like to avoid that kind of time investment. 

I've tried several variations of this with no luck. My guess is that I'm implementing .adderror incorrectly. I get this error:

 

SObject row does not allow errors Class.IdeaSolution.ideaIdToCase: line 176, column 6 Trigger.IdeaAfterUpdateAfterInsert: line 4, column 2: Class.IdeaSolution.ideaFromSolution: line 83, column 6

 

 

List<case> updateCases = New List<case>();
Case[] c = [select Idea__c,CaseNumber from case where id in :caseSolutionMap.keyset()];
for (Integer i = 0; i < c.size(); i++)
{
if (c[i].Idea__c != Null)
{
c[i].addError('There is already an idea associated with case ' + c[i].CaseNumber + '. This must be resolved before continuing.');
}
else
{
c[i].Idea__c = solutionIdeaMap.get(caseSolutionMap.get(c[i].id));
updateCases.add(c[i]);
}
}
update updateCases;

 

 

 

Message Edited by ehartye on 06-17-2009 10:14 AM

I got this error trying to deploy some test code: 

 

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>

 

Is anyone familiar with this? 

Sooo... you'll probably be able to tell by my crazy code that I've been round and round with this one, but all I want to do is assign a solution category based on the user's drop-down selection on the originating case. I ensure the dropdown selections always correspond with a solution category using a seperate process.

 

The dropdown field is "feature_area__c". 

 

My test code all passes fine, but when I execute this, I get the awesome "An error has occurred while processing your request."

 

 

public static void AssignSolutionCategory(solution[] solutions)
{
Map<Id,string> solutionCaseMap = New Map<Id,string>();
List<string> solutionIdList = New List<string>();
for (CaseSolution cs : [Select SolutionId,CaseId from casesolution where SolutionId in :solutions])
{

//I do this to ensure I only have one case match per solution
if (solutionCaseMap.containsKey(cs.SolutionId)==false)
{
solutionCaseMap.put(cs.SolutionId,cs.CaseId);
solutionIdList.add(cs.SolutionId);
}
}
If (solutionCaseMap.size() > 0)
{
Map<Id,string> caseFeatureAreaMap = New Map<id, string>();
for (Case c : [Select Id,Feature_Area__c from case where id in (Select CaseId from casesolution where SolutionId in :solutionCaseMap.keySet())])
{
caseFeatureAreaMap.put(c.id, c.Feature_Area__c);
}
List<CategoryNode> categoryNodeList = New List<CategoryNode>();
for (CategoryNode cn : [Select Id,MasterLabel from categorynode])
{
categoryNodeList.add(cn);
}
List<CategoryData> category = New List<CategoryData>();
for (integer x = 0; x < categoryNodeList.size(); x++)
{
for (integer i = 0; i < solutionIdList.size(); i++)
{
If (caseFeatureAreaMap.get(solutionCaseMap.get(solutionIdList[i])) == categoryNodeList[x].MasterLabel)
{
CategoryData cd = new CategoryData();
cd.CategoryNodeId = categoryNodeList[x].id;
cd.RelatedSobjectId = solutionIdList[i];
category.add(cd);
}
}
}
insert category;
}

}

 

 P.S. -- What's the trick to pasting code into a post without all the formatting screwing up?? Woot figured it out! Firefox good, Chrome bad :P

Message Edited by ehartye on 06-15-2009 08:14 PM
Message Edited by ehartye on 06-15-2009 08:17 PM
Message Edited by ehartye on 06-15-2009 08:20 PM
Message Edited by ehartye on 06-15-2009 08:26 PM

Internal Salesforce.com Query Error

 

An unexpected error has occurred. Your solution provider has been notified. (ComboPack)

 

 

Oddly enough, as an administrator, the page loads fine for me, but no one else. Sadly, I don't get the email this generates, so I can't really do any kind of troubleshooting. Has anyone seen this? Does anyone know how to get the email sent to me rather than ComboPack?

Adding the VF page as an inline object to a standard page layout is not a viable option for my implementation.

 

Does anyone know of an example of someone re-creating the Chatter bar in VF?

Users created with an external .net app we've made aren't getting the email with their login info. How is that supposed to work?

Ok so here is the scenario.  We have an application object which contains information about several entities: 3 contacts and 3 custom objects we have called involvements, one associated with each person.  Inside of the involvement object we have a drop down list with several options and depending on the option you have selected different fields are displayed and different validation rules are applied.  I am not sure if that is what is causing me this issue, but anytime I attempt to insert a new application object I get this error being thrown:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger parseStudentApplication caused an unexpected exception, contact your administrator: parseStudentApplication: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Contact]: [Contact]: Class.StudentApplicationParser.Parse: line 182, column 9

 

The following is my trigger:

trigger parseStudentApplication on Application_For_Admission__c(after insert) {
    List<Application_For_Admission__c> studentApps = Trigger.new;
    {
        StudentApplicationParser sap = new StudentApplicationParser();
        sap.Parse(studentApps);
    } 
}

 

Here is the class that process the trigger:

public with sharing class StudentApplicationParser {
    public void Parse(List<Application_For_Admission__c> sas)
    {
        List<Contact> contacts = new List<Contact>();
        List<Account> accounts = new List<Account>();
        List<npe4__Relationship__c> relationships = new List<npe4__Relationship__c>();
        List<Involvement__c> involvements = new List<Involvement__c>();
        List<Semester__c> semesters = new List<Semester__c>();
        List<School__c> schools = new List<School__c>();
        for(Application_For_Admission__c sa : sas)
        {
            Contact student = new Contact();
            Account studentAcct = new Account();
            Contact mother = new Contact();
            Account motherAcct = new Account();
            Contact father = new Contact();
            Account fatherAcct = new Account();
            npe4__Relationship__c relToMother = new npe4__Relationship__c();
            npe4__Relationship__c relToFather = new npe4__Relationship__c();
            Involvement__c studentInvolvement = new Involvement__c();
            Involvement__c motherInvolvement = new Involvement__c();
            Involvement__c fatherInvolvement = new Involvement__c();
            student.FirstName = sa.First_Name__c;
            student.LastName = sa.Last_Name__c;
            student.Birthdate = sa.Birthdate__c;
            student.MailingStreet = sa.Student_Address__c;
            student.MailingCity = sa.City__c;
            student.MailingState = sa.State__c;
            student.MailingPostalCode = sa.Zip__c;
            student.OtherPhone = sa.Phone__c;
            student.npe01__PreferredPhone__c = 'Other';
            student.npe01__HomeEmail__c = sa.Student_Email_Address__c;
            student.npe01__Preferred_Email__c = 'Home';
            System.debug('Set all student fields');
            mother.FirstName = sa.Mother_First_Name__c;
            mother.LastName = sa.Mother_Last_Name__c;
            mother.npe01__HomeEmail__c = sa.Mother_Email_Address__c;
            mother.npe01__Preferred_Email__c = 'Home';
            mother.npe01__WorkPhone__c = sa.Mothers_Work_Phone__c;
            mother.OtherPhone = sa.Mothers_Home_Phone__c;
            mother.npe01__PreferredPhone__c = sa.Mother_Preferred_Phone__c;
            mother.npe01__WorkPhone__c = sa.Mothers_Work_Phone__c;
            mother.MobilePhone = sa.Mothers_Cell_Phone__c;
            if(sa.Mothers_Address__c == null)
            {   
                mother.MailingStreet = sa.Student_Address__c;
                mother.MailingCity = sa.City__c;
                mother.MailingState = sa.State__c;
                mother.MailingPostalCode = sa.Zip__c;
                System.debug('Set all mother fields with same address as child');
            }
            else
            {
                mother.MailingStreet = sa.Mothers_Address__c;
                mother.MailingCity = sa.Mothers_City__c;
                mother.MailingState = sa.Mothers_State__c;
                mother.MailingPostalCode = sa.Mothers_Zip__c;
                System.debug('Set all mother fields with own address');
            }
            father.FirstName = sa.Father_First_Name__c;
            father.LastName = sa.Father_Last_Name__c;
            father.npe01__HomeEmail__c = sa.Father_Email_Address__c;
            father.npe01__Preferred_Email__c = 'Home';
            father.npe01__WorkPhone__c = sa.Fathers_Work_Phone__c;
            father.OtherPhone = sa.Fathers_Home_Phone__c;
            father.npe01__PreferredPhone__c = sa.Father_Preferred_Phone__c;
            father.npe01__WorkPhone__c = sa.Fathers_Work_Phone__c;
            father.MobilePhone = sa.Fathers_Cell_Phone__c;
            if(sa.Fathers_Address__c == null)
            {
                father.MailingStreet = sa.Student_Address__c;
                father.MailingCity = sa.City__c;
                father.MailingState = sa.State__c;
                father.MailingPostalCode = sa.Zip__c;
                System.debug('Set all father fields with same address as child');
            }
            else
            {
                father.MailingStreet = sa.Fathers_Address__c;
                father.MailingCity = sa.Fathers_City__c;
                father.MailingState = sa.Fathers_State__c;
                father.MailingPostalCode = sa.Fathers_Zip__c;    
                System.debug('Set all father fields with own address');         
            }
            relToMother.npe4__Contact__c = student.Id;
            relToMother.npe4__RelatedContact__c = mother.Id;
            relToMother.npe4__Description__c = 'Parent/Child';      
            relToMother.npe4__Status__c = 'Active'; 
            relToMother.npe4__Type__c = 'Family';
            System.debug('Set relationship to mother');
            relToFather.npe4__Contact__c = student.Id;
            relToFather.npe4__RelatedContact__c = father.Id;
            relToFather.npe4__Description__c = 'Parent/Child';
            relToFather.npe4__Status__c = 'Active';
            relToFather.npe4__Type__c = 'Family';
            System.debug('Set relationship to father');
            //studentInvolvement.Contact__c = student.Id;
            //studentInvolvement.Involvement__r = student.Id;
            studentInvolvement.Involvement_Level__c = 'Student';
            //studentInvolvement.Academic_Semester__c = current.Id;
            studentInvolvement.Grade_Level__c = sa.Grade__c;
            studentInvolvement.Gender__c = sa.Gender__c;
            studentInvolvement.Race__c = sa.Race__c;
            studentInvolvement.Level_Enrolled__c = sa.Enrollment_Level__c;
            studentInvolvement.Date_of_Birth__c = sa.Birthdate__c;
            studentInvolvement.Place_of_Worship__c = sa.Worship_Place__c;
            Semester__c current;
            Integer semCount = [Select Count() From Semester__c a where name = :sa.Academic_Semester__c];
            if(semCount == 0)
            {
               current = new Semester__c(name = sa.Academic_Semester__c);
               semesters.add(current);
            }
            else
            {
                current = [Select Id From Semester__c where name = :sa.Academic_Semester__c];
            }

  • May 28, 2010
  • Like
  • 0

I keep getting Too many SOQL Queries when I thought I wrote a bulk trigger until I did dataloader on update.. to get the porevious records.. Here is my code:

 

trigger bulktriggerfd on Placement__c (before insert,before update,after insert) { 
//Place the dataset in a Map to what is common in both objects 
//What would be the same through out the objects
Map<Id, Placement__c> PLAC = new Map<Id, Placement__c>();
for (Integer i = 0; i < Trigger.new.size(); i++) {
    if (System.Trigger.isInsert) {
        PLAC.put(Trigger.new[i].Participant__c,Trigger.new[i]); 
    }
    else if(System.Trigger.isUpdate){
        PLAC.put(Trigger.old[i].Participant__c,Trigger.new[i]);  
    }
}
//New List view 
List<Contact> updatedconField = new List<Contact>();
List<Placement__c> updatedplacField = new List<Placement__c>();

if(System.Trigger.isUpdate){
for (Contact c : [SELECT id,AccountId FROM Contact WHERE Id in :PLAC.keySet()]) {
        Placement__c parentAccount = PLAC.get(c.id);
        If(parentAccount.End_Date__c==null){
            c.AccountId = parentAccount.School__c;
            c.Current_Placement__c = parentAccount.Id;
            c.Current_Founder__c = parentAccount.Founder__c;
            c.Current_Program_City__c = parentAccount.Program_City__c;   
            c.Current_Role__c  = parentAccount.Role__c;  
            c.Current_Additional_Role_Info__c = parentAccount.Additional_Role_Info__c;
            c.Current_Weeks_Placed_in_Advance__c = parentAccount.Weeks_Placed_in_Advance__c;
            c.Current_Description__c   = parentAccount.Description__c; 
        }  
        if(parentAccount.End_Date__c!=null){
            List<Placement__c> pl = [Select id from Placement__c Where Id in :PLAC.keySet() and End_Date__c=null];
            if(pl.size()>0){
            c.AccountId = pl[0].School__c;
            c.Current_Placement__c = pl[0].Id;
            c.Current_Founder__c = pl[0].Founder__c;
            c.Current_Program_City__c = pl[0].Program_City__c;   
            c.Current_Role__c  = pl[0].Role__c;  
            c.Current_Additional_Role_Info__c = pl[0].Additional_Role_Info__c;
            c.Current_Weeks_Placed_in_Advance__c = pl[0].Weeks_Placed_in_Advance__c;
            c.Current_Description__c   = pl[0].Description__c; 
            }
            if(pl.size()==0){
            c.Current_Placement__c = null;
            c.Current_Program_City__c = null;   
            c.Current_Role__c  = null;  
            c.Current_Additional_Role_Info__c = null;
            c.Current_Weeks_Placed_in_Advance__c = null;
            c.Current_Description__c   = null;
            }
        }     
        System.Debug('parentAccount -  ' + parentAccount);
        
        updatedconField.add(c);
    }
    } 

if(System.Trigger.isInsert){
for (Contact c : [SELECT id,AccountId,Current_Placement__c FROM Contact WHERE Id in :PLAC.keySet()]) {
        Placement__c parentAccount = PLAC.get(c.id);
        If(parentAccount.End_Date__c==null){
            c.AccountId = parentAccount.School__c;
            c.Current_Placement__c = parentAccount.Id;
            c.Current_Founder__c = parentAccount.Founder__c;
            c.Current_Program_City__c = parentAccount.Program_City__c;   
            c.Current_Role__c  = parentAccount.Role__c;  
            c.Current_Additional_Role_Info__c = parentAccount.Additional_Role_Info__c;
            c.Current_Weeks_Placed_in_Advance__c = parentAccount.Weeks_Placed_in_Advance__c;
            c.Current_Description__c   = parentAccount.Description__c;             
            System.Debug('id = ' + parentAccount.Id);
        }
        System.Debug('parentAccountnew -  ' + parentAccount);
        
        updatedconField.add(c);
}
}    
    
    update updatedconField;
}

 

Thanks

 

Hi,

 

Colleagues are required to add attachments to Opportunities that they do not own, however there is no possible way using standard salesforce functionality to send an email alert to the Opportunity owner.

 

Does anyone know how I can achieve this using triggers?

 

Your help would be much appreciated! Thanks...

  • May 28, 2010
  • Like
  • 0

 

I'm trying to write a function to merge comments and posts from one feed to another. Sadly I get this error (from the debug log) :

 

 


13:28:14.418|SOQL_EXECUTE_BEGIN|[343,39]|Aggregations:0|SELECT id, FeedPost.Body from ChatterTasks__ToDoItem__Feed where id = '0D5A0000000GoXbKAK' limit 1
13:28:14.431|SOQL_EXECUTE_END|[343,39]|Rows:1|Duration:13
13:28:14.431|METHOD_EXIT|[343,39]|query(String)
13:28:14.431|METHOD_ENTRY|[347,47]|SObject.get(String)
13:28:14.431|METHOD_EXIT|[347,47]|get(String)
13:28:14.431|METHOD_ENTRY|[348,52]|SObject.get(String)
13:28:14.431|EXCEPTION_THROWN|[348,52]|System.SObjectException: Invalid field FeedPost.Body for ChatterTasks__ToDoItem__Feed

 

 

When I run this code:

 

 

               for(String id : activeSObjectFeedItems) {
try {
String feedObjectName = feedObjectName(activeSObjectType);
String queryString = 'SELECT id, FeedPost.Body from ' + feedObjectName + ' where id = \'' + id + '\' limit 1';
List<SObject> sos = Database.query(queryString);
FeedComment fcomment = new FeedComment();
fcomment.FeedItemId = (Id) sos[0].get('id');
fcomment.CommentBody = (String) sos[0].get('FeedPost.Body');
insert fcomment;
}
catch(Exception e) {
System.debug('MergeFeed: ' + e);
}
}

 

But I can't think of a workaround since I can't query the FeedPosts directly.

 

Ideas?