Trigger Apex to create a Prospect Contact with Opportunity Earned

0
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');
    }
}
    
asked by Eduardo Cordero 10.07.2018 в 23:22
source

0 answers