function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Simon234Simon234 

Trigger LeadConvert and Opportunity Name change

Hello. I need to convert a Lead with LeadConvert and change an opp's Name like this: 'AccountName + DateTime.now'. How can I do that? This doesn't work:

for (Lead lead : Trigger.new) { 
        if (lead.isConverted == false && lead.Status == 'Closed - Converted') {
            lc.setLeadId(lead.Id);   
            lc.setConvertedStatus(convertStatus.MasterLabel);
            lcList.add(lc);
            
            String s = String.valueOf(lc.getAccountId());
         	String b = String.valueOfGmt(Datetime.now());
            lc.setOpportunityName(s + b);
            
            List<Database.LeadConvertResult> lcrList = Database.convertLead(lcList,false);
     }
I become 'null+DateTime.now'. How can I take AccName before Database.convertLead? :( 
Raj VakatiRaj Vakati
Refer this link 

https://help.salesforce.com/articleView?id=000220247&type=1


 
PawanKumarPawanKumar
You do it by using the workflow concept. You right WF on the opportunity created.
Raj VakatiRaj Vakati
This link is having details steps 

https://help.salesforce.com/articleView?id=000220247&type=1
 
Simon234Simon234
No WF. I write in Developer forum, guys, so I need a clear code-Trigger.
Chaitra Padashetty 23Chaitra Padashetty 23
Did anybody find solution to this? why doesnt the lc.setOpportunityName work?