+ Start a Discussion
Sujan Kumar ReddySujan Kumar Reddy 

Interview question: Awaiting replies from experts

Hi,

 

Interview question: Awaiting replies from experts

 

Q: I have the following requirement. Please write a trigger for it

I have two objects Leave_Application__c and Leave__c 

Leave__c has Master Detail relationship with Leave_Application__c

There is a picklist field in Leave_Application__c object named Status__c

Now whenever a Status__c field is updated to the value "Approved"  a recordshould be created in Leave__c object . Newly created record will have one field that is Leave_Application_No__c and that should be set to the trigger ID.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
MagulanDuraipandianMagulanDuraipandian

trigger slaCheck on Leave_Application__c(after Update, after Insert)
{
    for(Leave_Application__c acc:trigger.New)
    {
        if(Leave_Application__c.Status__c == 5)
        {
            Leave__c con = new Leave__c(Leave_Application_No__c  = ur value, Leave_Application__c=acc.ID);
            Insert con;
        }
    }
}

 

Regards,

Magulan D

Salesforce.com certified Force.com Developer.

SFDC Blog

If this post is your solution, kindly mark this as the solution.