• srk goud
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
converting lead
Trigger AutoConverter on Lead (after insert)
{ LeadStatus convertStatus = [ select MasterLabel from LeadStatus where IsConverted = true limit 1 ];
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
for (Lead lead: Trigger.new) {
if (!lead.isConverted && lead.WebForm__c == 'Free Trial') {
Database.LeadConvert lc = new Database.LeadConvert();
String oppName = lead.Name;
lc.setLeadId(lead.Id);
lc.setOpportunityName(oppName);
lc.setConvertedStatus(convertStatus.MasterLabel);
leadConverts.add(lc); }
}
if (!leadConverts.isEmpty())
{ List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
}
}
here why we have taken isconverte=true....
trigger TriggerAccountContacts on Account (after insert) {
list<contact> cons=new list<contact>();
    for(account a:trigger.new){
        contact c=new contact();
        c.lastname=a.name;
        c.Phone=a.phone;
        c.Description=a.description;
        c.AccountId=a.id; //what is accountid here is it record id of account object
        cons.add(c);
    }
    insert cons;
}
converting lead
Trigger AutoConverter on Lead (after insert)
{ LeadStatus convertStatus = [ select MasterLabel from LeadStatus where IsConverted = true limit 1 ];
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
for (Lead lead: Trigger.new) {
if (!lead.isConverted && lead.WebForm__c == 'Free Trial') {
Database.LeadConvert lc = new Database.LeadConvert();
String oppName = lead.Name;
lc.setLeadId(lead.Id);
lc.setOpportunityName(oppName);
lc.setConvertedStatus(convertStatus.MasterLabel);
leadConverts.add(lc); }
}
if (!leadConverts.isEmpty())
{ List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
}
}
here why we have taken isconverte=true....
trigger TriggerAccountContacts on Account (after insert) {
list<contact> cons=new list<contact>();
    for(account a:trigger.new){
        contact c=new contact();
        c.lastname=a.name;
        c.Phone=a.phone;
        c.Description=a.description;
        c.AccountId=a.id; //what is accountid here is it record id of account object
        cons.add(c);
    }
    insert cons;
}