You need to sign in to do that
Don't have an account?
Harry1008
Trigger on ContentVersion on Lead
Hi All,
I wrote a Trigger on ContentVersion. The requirement is when I upload a file on the lead when the lead is only on the status "Engagement" then the status should change to "Negotiation". with the below trigger which ever the status is if I upload the file the lead status is changing to "Converted".
Could someone help please.
I wrote a Trigger on ContentVersion. The requirement is when I upload a file on the lead when the lead is only on the status "Engagement" then the status should change to "Negotiation". with the below trigger which ever the status is if I upload the file the lead status is changing to "Converted".
Could someone help please.
trigger FileUploadonLead on ContentVersion (after insert) { map <id,string> lmap = new map <id,string>(); list<lead> leadlist = new list <lead>(); for(contentversion cv : trigger.new){ id x = cv.FirstPublishLocationId; if(string.valueof(x.getsobjecttype()) == 'lead'){ system.debug('inside test'); lmap.put(cv.FirstPublishLocationId,'Negotiation'); } } for(lead l : [select id,status from lead where id in : lmap.keySet()]){ l.status = lmap.get(l.id); leadlist.add(l); } if(leadlist.size()>0){ update leadlist; } }
I would suggest making the above change and running the same UI test as noted.
*note: the check for the Status could also be made when you are creating the Map.
Regards
Andrew
All Answers
The trigger look innocuos - not quite the way I would write it, but the logic is there.
My questions would be
1. What is the behaviour if the Trigger is commented out and does not run?
2. With the trigger in place, have you done a debug on list prior to the update, to see what the status is prior to Update? Something like 3. On your Status Picklist values, is Converted an actual status or are you saying the lead is converted (i.e. Account created).?
If answer to 1 is that the Status still ends up as 'Converted', good news - the trigger is not the culprit. Bad news - what is? perhaps check Process builder or check the debug logs for any other triggers firing. Maybe on the Lead itself.
If answer to 1 is that status does not go 'Converted', and the answer to the question 2 is that the debug log shows the values and statuses correctly, then digging in the debug logs for what is changing after that. Check in your Lead object for other triggers perhaps.
question 3 is just for clarity on where your question is - example :
HTH
Andrew
1) The behaviour is normal and the status not moving to Converted. We have different statuses on Lead.
2) The status prior to the update is "Engagement".
3) On status picklist it ends up with Converted not converted to Account.
There are no other triggers or Process builder that changes the status.
Could you please assist me on how to solve the issue.
The requirement is when I upload the file only when the status is "Engagement" it should update the status to "Negotiation".
Thank you for your time in advance.
Kind Regards
Harry
I would suggest making the above change and running the same UI test as noted.
*note: the check for the Status could also be made when you are creating the Map.
Regards
Andrew