trigger OppLeadtoClient on Opportunity (Before update) {
If(trigger.new[0].StageName=='Closed Won'){
Lead ld = [SELECT Id FROM Lead WHERE accountid__c =: trigger.new[0].Accountid ];
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(ld.Id);
lc.setDoNotCreateOpportunity(True);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
System.debug('converted');
}
}