• Robert Cheek
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
PLZ HELP ME HOW GET ConvertedAccountid TO WHICH LEAD IS GEETING CONVERTED
IT IS SHOWING NULL IN SYSTEM DEBUG.
trigger converted on Lead (after insert)
{
set<id> s= new set<id>();
list<account> acc = new list<account>();
list<contact> cs = new list<contact>();
list<task> tsk = new list<task>();
list<opportunity> ops = new list<opportunity>();
for (lead ls:trigger.new)
{

s.add(ls.id);

}
for(lead l:[select id,ConvertedAccountId,company from lead where id in:s])
{
 system.debug('*************ConvertedAccountId************'+l.ConvertedAccountId);
account a = new account();
a.id = l.ConvertedAccountId;
a.name = l.company;

acc.add(a);
system.debug('@@@@@@'+a);
opportunity o = new opportunity();
o.name = l.company;
o.accountid = l.ConvertedAccountId;
o.StageName = 'Prospecting';
o.CloseDate = system.today();

ops.add(o);
system.debug('@@@@@@'+o);
task t = new task();
t.subject = 'converted lead task';
t.whatid = l.ConvertedAccountId;
t.priority = 'Normal';
t.status = 'Not Started';

tsk.add(t);
system.debug('@@@@@@'+t);
contact c = new contact();
c.lastname = l.company;
c.accountid = l.ConvertedAccountId;

cs.add(c);
system.debug('@@@@@@'+c);
}
insert acc;
insert cs;
insert tsk;
insert ops;


}