function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SMasterSMaster 

How to create a new record while Attachment, with record name as an Attached file name??

Hi All,
How can i achieve this...
vanessenvanessen

i think you should be more clear in your description of the problem.So that we can help.

SMasterSMaster
Hi,

 

I need to create a new record in the related list.. but that record should get created only after i attached a file to it...

 

i mean... in order to create the record in the related list of an opportunity first i'll upload the file.. and with the uploaded file name will become the record name... and the new record will be created...

 

Thanks

Pradeep_NavatarPradeep_Navatar

You have to write a trigger on Attachment using Eclipse. Open your Org in Eclipse then create a new trigger where you will get a picklist to select the Attachment Object. This is only the way to write a trigger on Attachment. Find below a sample code :

 

// Trigger to create a record in RelatedList_Obj__c object that is child object of Opportunity if Opportunity have any attachment.

 

            trigger TiggerName on attachment(after insert)

            {          

                        String OppAsParentId = Trigger.New[0].ParentId;

                        OppAsParentId = OppAsParentId.substring(0,3);

 

                        if(OppAsParentId == '006')

                        {

                                    RelatedList_Obj__c ro = new(name=:Trigger.New[0].name, Opportunity_lookup__c=:Trigger.New[0].ParentId);                                                                 

                                    Insert ro;

                        }

            }

SMasterSMaster

Sir,

 

I am getting the following error while implementing this code....

 

Save error: line 8:121 no viable alternative at character '​'