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
adiazadiaz 

Create new entry in a different object

I created 2 custom objects as a logging tool; Suppor Ticket and Maintenance Requests.

 

I have a field called type in the maintenance object. I would like a new entry to be created in the support ticket object if the field Type (in maintinance object) is changed to Support Required. Is this possible without Apex coding?

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

I dont know whether you still require answer for this or not.

If yes then use the below code and replace accordingly with your details.

trigger <<triggername>> on Maintainance__c(after update)

{

    if(Trigger.isUpdate){
        for(Maintainance__c m: Trigger.new)

       {

          if(m.Type__c == 'Support Required')

          {

               SupportTicket__c st = new SupportTicket__c();

               //do your stuff, for ex

                st.xyz = m.xyz;

                insert st;

          }
         
        }
    }  

}

 

Let me know if you have any questions.

 

All Answers

aalbertaalbert

I do not believe so. You would have to write an Apex Trigger.

Pradeep_NavatarPradeep_Navatar

It can not be achieved through standard functionality, you need to create a trigger for that.

adiazadiaz

Thanks for the reply. I have very little apex code knowledge. Can someone point me in the right direction? perhaps a similar code where i have to replace fields/objects name? Thanks

Imran MohammedImran Mohammed

I dont know whether you still require answer for this or not.

If yes then use the below code and replace accordingly with your details.

trigger <<triggername>> on Maintainance__c(after update)

{

    if(Trigger.isUpdate){
        for(Maintainance__c m: Trigger.new)

       {

          if(m.Type__c == 'Support Required')

          {

               SupportTicket__c st = new SupportTicket__c();

               //do your stuff, for ex

                st.xyz = m.xyz;

                insert st;

          }
         
        }
    }  

}

 

Let me know if you have any questions.

 

This was selected as the best answer
adiazadiaz

Works perfectly! Thanks!

adiazadiaz

Okay I've written my code and tested it in my sandbox; works as expected. When I tried to move it to production, I ran a the deployement test and I received the following msg: "Coverage of selected Apex Trigger is 0%...." I browsed the boards for an answer but everything I tried didn't work. Can someone help me write a test class?

 

Below is my Trigger Code:

 

 

trigger CreateTicket on Maintenance_Request__c(after update)

{

    if(Trigger.isUpdate){
        for(Maintenance_Request__c m: Trigger.new)

       {

          if(m.Status__c == 'Pending Support')

          {

               Support_Team_Request__c st = new Support_Team_Request__c();

               //do your stuff, for ex

                  st.Your_name__c = m.Your_Name__c;
                  st.Client_reported_issue__c = 'No';
                   st.Short_description__c = m.Short_Description__c;
                   st.Client_Name__c = m.Client_Name__c;
                   st.Description_of_Issue__c = m.Detailed_Description__c;
                    st.Mailbox__c = m.Mailbox__c;
                    st.Priority__c = 'medium';
                    st.Created_From_MTR__c = 'Yes';
                    st.Request_Type__c = 'production' ;  
                    st.Participant_Name__c = m.Participant_Name__c;
                    st.Participant_ID__c = m.Participant_ID__c;
                    st.CC_Contact__c = m.CC_Contact__c;

                insert st;

          }
         
        }
    }  

}