You need to sign in to do that
Don't have an account?
Harry1008
Having trouble on lead status update via apex trigger
Hi All,
I have written a Trigger to update the lead status from Engagement to Negotiation when a file is uploaded on Lead when the status is Engagement. I want to restrict the trigger to fire when the file is uploaded on Engagement status and update the status to negotiation thats it. The trigger should not fire if the lead is on another status and if a user upload the file. Could you please help me how to achieve this in the below code.
I have written a Trigger to update the lead status from Engagement to Negotiation when a file is uploaded on Lead when the status is Engagement. I want to restrict the trigger to fire when the file is uploaded on Engagement status and update the status to negotiation thats it. The trigger should not fire if the lead is on another status and if a user upload the file. Could you please help me how to achieve this in the below code.
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()]){ system.debug('lmap.get() '+ lmap.get(l.id) ); l.status = lmap.get(l.id); leadlist.add(l); } if(leadlist.size()>0){ system.debug('leadlist ' + leadlist ); update leadlist; } }
All Answers