my apex class is not visible in Apex Action in flow builder. kindly suggest...... I shall be grateful to you for quick response.
Global class ConvertLeadAction1 {
@InvocableMethod(label='Convert Leads without opp' description ='not to create opps')
global static List<ConvertLeadActionResult> convertLeads1(List<ConvertLeadActionRequest> requests) {
List<ConvertLeadActionResult> results = new List<ConvertLeadActionResult>();
for (ConvertLeadActionRequest request : requests) {
results.add(convertLead1(request));
}
return results;
}
public static ConvertLeadActionResult convertLead1(ConvertLeadActionRequest request) {
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(request.leadId);
lc.setConvertedStatus('Konvertiert');
if (request.accountId != null
&& request.accountId != 'null'
&& request.accountId != ''
&& request.accountId != ' ') {
lc.setAccountId((ID)request.accountId);
}
if (request.contactId != null
&& request.contactId != 'null'
&& request.contactId != ''
&& request.contactId != ' ') {
lc.setContactId((ID)request.contactId);
}
if (request.OpportunityId == null
&& request.OpportunityId == 'null'
&& request.OpportunityId == ''
&& request.OpportunityId == ' '
&& request.OpportunityId != 'CreateOpportunity'
&& request.OpportunityId == 'false') {
lc.setDoNotCreateOpportunity(True);
}
Database.LeadConvertResult lcr = Database.convertLead(lc, true);
if (lcr.isSuccess()) {
ConvertLeadActionResult result = new ConvertLeadActionResult();
result.accountId = lcr.getAccountId();
if(request.accountId == null
|| request.accountId == 'null'
|| request.accountId == ''
|| request.accountId == ' '){
Account acc = [SELECT Id, CurrencyIsoCode, Type FROM Account WHERE Id =: result.accountId LIMIT 1];
acc.CurrencyIsoCode = request.accounttIsoCode;
acc.Type = request.accountCompanyType;
update acc;
}
result.contactId = lcr.getContactId();
if(request.contactId == null
|| request.contactId == 'null'
|| request.contactId == ''
|| request.contactId == ' '){
Contact cont = [SELECT Id, CurrencyIsoCode FROM Contact WHERE Id =: result.contactId LIMIT 1];
cont.CurrencyIsoCode = request.accounttIsoCode;
update cont;
}
//if(result.opportunityId == null){
if(request.createOpportunity != true){
result.opportunityId = lcr.getOpportunityId();
Opportunity opp = [SELECT Id, RecordTypeId, StageName, isFromLeadConvert__c,
CloseDate, Termin_Live_Demo__c, Produkt__c,
FROM Opportunity
WHERE Id =: result.opportunityId LIMIT 1];
opp.RecordTypeId = request.oppRecordType;
opp.CloseDate = request.oppClosedDate;
opp.PrimaryContact__c = result.contactId;
if(request.oppTerminLiveDemo != NULL){
opp.Termin_Live_Demo__c = request.oppTerminLiveDemo;
}
opp.Produkt__c = request.oppProdukt;
opp.CurrencyIsoCode = request.oppIsoCode;
opp.OwnerId = request.oppOwnerId;
opp.isFromLeadConvert__c = false;
update opp;
}
return result;
} else {
throw new ConvertLeadActionException(lcr.getErrors()[0-10].getMessage());
}
}
global class ConvertLeadActionRequest {
@InvocableVariable
global ID oppOwnerId;
@InvocableVariable(required=true)
global ID leadId;
@InvocableVariable
global String accountId;
@InvocableVariable
global String OpportunityId;
@InvocableVariable
global String contactId;
@InvocableVariable
global String accountCompanyType;
@InvocableVariable
global Boolean createOpportunity;
@InvocableVariable
global String accounttIsoCode;
@InvocableVariable
global String contactIsoCode;
@InvocableVariable
global ID oppRecordType;
@InvocableVariable
global String oppIsoCode;
@InvocableVariable
global String oppStage;
@InvocableVariable
global Date oppClosedDate;
@InvocableVariable
global DateTime oppTerminLiveDemo;
@InvocableVariable
global String oppProdukt;
}
global class ConvertLeadActionResult {
@InvocableVariable
global ID accountId;
@InvocableVariable
global Id contactId;
@InvocableVariable
global ID opportunityId;
@InvocableVariable
global Boolean createOpportunity;
}
class ConvertLeadActionException extends Exception {}
}
2 Antworten
Hi Nishant,
I'm able to see the invocable method from apex action in Ligjting Flow without any issue. You might need to refresh the flow to see the method.