Activity Forums Salesforce® Discussions Salesforce Trigger is not working, anyone help me with this code

  • Salesforce Trigger is not working, anyone help me with this code

    Posted by Raghav Chaturvedi on May 10, 2018 at 10:48 am

    Create object : Condidate__c
    Fields : (All Text fields)
    First Name
    Last Name
    Email
    Brokerage
    Manage Brokerage
    Condidate Status (Webinar - Attended , Webinar -Not Attended)
    User Created ( checkbox)
    On insert:

    1. Create Account if Brokerage !=null
    2. Create another account if Manage Brokerage != null and set parentId = Brokerage account id (created in 1 point)
    3. Create new contact record and set accountId = Manage Brokerage account id (created in 2 point)
    4. create new field condidate__c(lookup) on contact and fill it with Condidate__c record id
    5. Create task record for contact record (created in point 3)

    Task.WhoId = contactId
    Task.WhatId = Condidate__c
    Task.Subject = 'Portal Contact Setup';
    On Update :
    if Condidate__c  Status = Webinar - Attended and User Created = false ,
    Create Portal user for Condidate child contact created in 3 point.

    trigger CreateContactcase on Hire_Form__c (before insert,before update){
    list<Contact> conlist=new list<Contact>();
    list<case> caselist=new list<case>();
    if(trigger.isinsert){
    for(Hire_Form__c hire:trigger.new){
    if(hire.Status__c=='In Progress'){
    Contact con=new Contact();
    con.FirstName='Hire';
    con.LastName='Trigger';
    con.Email='[email protected]';
    con.Phone='123456';
    conlist.add(con);
    //hire.Candidate__c=con.Id;
    }
    }
    insert conlist;
    system.debug('=====>'+conlist);
    for(Contact con1:conlist){
    case cc=new case();
    cc.ContactId=con1.Id;
    cc.Status='New';
    cc.Origin='Phone';
    //cc.Id=conlist[0].Id;
    caselist.add(cc);
    }
    insert caselist;
    system.debug('=====>'+caselist);
    }
    if(Trigger.isupdate){
    for(Hire_Form__c hire:trigger.new){
    for(case c:caselist){
    if(hire.Status__c=='completed' && hire.Status__c !=trigger.oldmap.get(hire.Id).Status__c){
    c.Status='closed';
    }
    }
    update caselist;
    system.debug('====>'+caselist);
    }
    }
    }
    
    Raghav Chaturvedi replied 6 years, 6 months ago 1 Member · 0 Replies
  • 0 Replies

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

Popular Salesforce Infographics