+ Start a Discussion
Jennifer24wJennifer24w 

Trigger when attachment is inserted: help!

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);
VamsiVamsi
Hi,

If you need to run a particular set of code when an attachment is added up to a record then you need to have a code running on Attachment object.

Get the parent ID from newly inserted attachment and verify if its a contact and then run the required code 
Shivdeep KumarShivdeep Kumar
Hi Jennifer,

As per your requirement, when you inserted the attachement which is related to contact and then filter with some fields. after that you are calling a apex class method (addAllAttachments.getAttachmentsForStudent(x,y)).
Please try to write the trigger in attachment and with the help of schema know the sobject type(Contact).
OR 
show the code of apex class so that i can dig on it to help you.

Thanks
Shivdeep