• siva ss
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
iam new to salesforce how to write the test class bleow  code explain any one 


trigger Conference on User__c (after insert,after Update) 
{
    //Checking the Data Inserting || updating
    if(Trigger.isInsert || Trigger.isUpdate)
    {
        // fetching newly added User__C from Conference__c 
        list<Conference__c> conference = [SELECT Id,ConferenceName__c,Location__c,StartDate__c,Detail__c,EndDate__c,(select id,Name__c, Email__c,Relationship__c from Users__r where id in:Trigger.newMap.keySet())
                                          FROM Conference__c where id in (select Relationship__c From User__c where Id =:Trigger.newMap.keySet())];
        // Checking the Condition either value is their or Not
        if(!conference.IsEmpty())
        {
            // Conference Loop For (Parent-Object) 
            for(Conference__c con : conference)
            {
                //User Loop For (Child-Object) 
                for(User__c use : con.Users__r)
                {
                    //Checking the Condition Whether Relationship is Empty or Value
                    if(use.Relationship__c != null)
                    {
                        con.Id = use.Relationship__c;
                        
                        // Step 1: Create a new Email
                        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                        // Step 2: Set list of people who should get the email
                        List<String> sendTo = new List<String>();
                        sendTo.add(use.Email__c);  
                        mail.setToAddresses(sendTo);
                        
                        // Step 3: Set who the email is sent from
                        mail.setReplyTo(use.Email__c);
                        mail.setSenderDisplayName('Export Solutions and Techonologies');
                        
                        // Step 4. Set email contents - you can use variables!
                        mail.setSubject('URGENT BUSINESS COnfernce ');
                        String body = 'Dear ' +use.Name__c  + ',<br/> ';
                        body += 'Conference Name:' +con.ConferenceName__c+',<br/>';
                        body += 'Location:' +con.Location__c+',<br/>';
                        body += 'StartDate:' +con.StartDate__c+',<br/>';
                        body += 'StartDate:' +con.EndDate__c+',<br/>';
                        body += 'Detail:' +con.Detail__c+',<br/>';
                        body += 'Your Added This Metting .<br/>';
                        mail.setHtmlBody(body);
                        
                        // Step 6: Send all emails in the master list
                        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                    }
                }
            }
        } 
    }
}