• Jennifer24w
  • NEWBIE
  • 10 Points
  • Member since 2018
  • CRM Administrator/Programmer
  • Moravian College

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
I'm new to writing Triggers this is my first one wirtten without help.  I'm not sure where I'm going wrong here but this is what I need it to do.  If the stage field is updated to Forfeit or Withdraw after action I need it to reomve all data in the fields in the trigger.  I got this up and running, but one issue.  It's basically making the fields null even when the stage isn't one of those two values.  I'm not sure where I'm going wrong with this.  Any help would be appreciated.

trigger RemoveUDF on Contact (before update) {
    for (Contact cont : Trigger.New)
    {
      If (cont.TargetX_SRMb__Student_Type__c == 'First-Time Freshman'&& (cont.TargetX_SRMb__Status__c == 'Forfeit'|| cont.TargetX_SRMb__Status__c == 'Withdraw-Stu WD After Act'))    
      {
            cont.Moravian_CA_UDEF_3A_3__c = Null;
            cont.Moravian_CA_UDEF_1A_4__c = Null;
            cont.Moravian_CA_UDEF_10A_1__c = Null;
            cont.Moravian_CA_UDEF_1A_10__c = Null;
            cont.Moravian_CA_UDEF_1A_1__c = Null;
            cont.Moravian_CA_UDEF_1A_2__c = Null;
            cont.Moravian_CA_UDEF_1A_3__c = Null;
            cont.Moravian_CA_UDEF_1A_5__c = Null;
            cont.Moravian_CA_UDEF_1A_6__c = Null;
            Cont.Moravian_CA_UDEF_1A_7__c = Null;
            Cont.Moravian_CA_UDEF_1A_8__c = Null;
            Cont.Moravian_CA_UDEF_1A_9__c = Null;
            Cont.Moravian_CA_UDEF_2A_1__c = Null;
            Cont.Moravian_CA_UDEF_2A_2__c = Null;
            Cont.Moravian_CA_UDEF_2A_3__c = Null;
            Cont.Moravian_CA_UDEF_3A_2__c = Null;
            Cont.Moravian_CA_UDEF_3A_3__c = Null;
            Cont.Moravian_CA_UDEF_3A_4__c = Null;
            Cont.Moravian_CA_UDEF_5A_1__c = Null;
            Cont.Moravian_CA_UDEF_5A_2__c = Null;
            Cont.Moravian_CA_UDEF_5A_3__c = Null;
            Cont.Moravian_CA_UDEF_5A_4__c = Null;
        }     
    }
}
I'm hoping someone can help.  We have a vendor that wrote this code for us (see below). I'm trying to run an Informatica task that updates some users records and this is the error I'm getting.  

Error loading into target [Contact] : Error received from salesforce.com.  Fields [].  Status code [CANNOT_MODIFY_MANAGED_OBJECT].  Message [addToCList: execution of AfterUpdatecaused by: System.QueryException: List has more than 1 row for assignment to SObject()].

I am updating 14 contact records but keep getting a failure and this message is what it's telling me.  But I don't understand what the problem is that is causing this message.  Hopefully someone can help me understand what is happening here.  I'm not a developer but I do understand what is written in the code, I just don't know why it's giving me this partiuclar error.  TIA for any assistance.  



Apex Code
trigger addToCList on Contact (after update) {
for (Contact cont : Trigger.New)
{

if (cont.Jenzabar_ID__c !=null)
{
if (cont.TargetX_SRMb__Student_Type__c=='First-Time Freshman'||cont.TargetX_SRMb__Student_Type__c=='International Freshman')
{
if (cont.TargetX_SRMb__Status__c=='Deposit Paid')
{
addAllAttachments.getAttachmentsForStudent(cont.X18_digit_ID__c,cont.Jenzabar_ID__c);
}
} else 
{
if (cont.TargetX_SRMb__Status__c=='Accept')
{
addAllAttachments.getAttachmentsForStudent(cont.X18_digit_ID__c,cont.Jenzabar_ID__c);

 
Ok here is what the problem is.  We have an outside vendor that I writing some code in our system.  The issue is that their code is now interferring with our code and causing me headaches with Process builders.  I'm not a coder so I thought I'd try to come to you for help here first.  I don't think Salesforce is something they understand enough to get this correct.  The problem is that they have this code running on update of a contact, and when I change the owner of an account it auto updates the contact owners to match through a process builder (again not a coder so this is how we made that work), their code is now firing every time this is being updated and giving me process flow errors left and right.  It's not just that Process Builder either its acutally several of them.  I have asked them to fix the code they changed something that did nothing.  What I need I think is for this code to fire off when an attachemnt is added to a contact record, not when the contact record is updated.  Any assistance in fixing this would be greatly appreciated.  

trigger addToCList on Contact (after update) {
for (Contact cont : Trigger.New)
{

if (cont.Jenzabar_ID__c !=null)
{
if (cont.TargetX_SRMb__Student_Type__c=='First-Time Freshman'||cont.TargetX_SRMb__Student_Type__c=='International Freshman')
{
if (cont.TargetX_SRMb__Status__c=='Deposit Paid')
{
addAllAttachments.getAttachmentsForStudent(cont.X18_digit_ID__c,cont.Jenzabar_ID__c);
}
} else 
{
if (cont.TargetX_SRMb__Status__c=='Accept')
{
addAllAttachments.getAttachmentsForStudent(cont.X18_digit_ID__c,cont.Jenzabar_ID__c);
I'm new to writing Triggers this is my first one wirtten without help.  I'm not sure where I'm going wrong here but this is what I need it to do.  If the stage field is updated to Forfeit or Withdraw after action I need it to reomve all data in the fields in the trigger.  I got this up and running, but one issue.  It's basically making the fields null even when the stage isn't one of those two values.  I'm not sure where I'm going wrong with this.  Any help would be appreciated.

trigger RemoveUDF on Contact (before update) {
    for (Contact cont : Trigger.New)
    {
      If (cont.TargetX_SRMb__Student_Type__c == 'First-Time Freshman'&& (cont.TargetX_SRMb__Status__c == 'Forfeit'|| cont.TargetX_SRMb__Status__c == 'Withdraw-Stu WD After Act'))    
      {
            cont.Moravian_CA_UDEF_3A_3__c = Null;
            cont.Moravian_CA_UDEF_1A_4__c = Null;
            cont.Moravian_CA_UDEF_10A_1__c = Null;
            cont.Moravian_CA_UDEF_1A_10__c = Null;
            cont.Moravian_CA_UDEF_1A_1__c = Null;
            cont.Moravian_CA_UDEF_1A_2__c = Null;
            cont.Moravian_CA_UDEF_1A_3__c = Null;
            cont.Moravian_CA_UDEF_1A_5__c = Null;
            cont.Moravian_CA_UDEF_1A_6__c = Null;
            Cont.Moravian_CA_UDEF_1A_7__c = Null;
            Cont.Moravian_CA_UDEF_1A_8__c = Null;
            Cont.Moravian_CA_UDEF_1A_9__c = Null;
            Cont.Moravian_CA_UDEF_2A_1__c = Null;
            Cont.Moravian_CA_UDEF_2A_2__c = Null;
            Cont.Moravian_CA_UDEF_2A_3__c = Null;
            Cont.Moravian_CA_UDEF_3A_2__c = Null;
            Cont.Moravian_CA_UDEF_3A_3__c = Null;
            Cont.Moravian_CA_UDEF_3A_4__c = Null;
            Cont.Moravian_CA_UDEF_5A_1__c = Null;
            Cont.Moravian_CA_UDEF_5A_2__c = Null;
            Cont.Moravian_CA_UDEF_5A_3__c = Null;
            Cont.Moravian_CA_UDEF_5A_4__c = Null;
        }     
    }
}