[
  {
    "name": "convertLead",
    "label": "Convert Lead",
    "description": "Salesforce-compatible Lead Convert. Routes through the Std_ConvertLead flow so tenants customise behavior (defaults, guards, child relink) as data without backend changes.",
    "flowDeveloperName": "Std_ConvertLead",
    "category": "LeadActions",
    "requiredPermissions": ["ConvertLeads"],
    "targetObjects": ["Lead"],
    "isAtomic": true,
    "sortOrder": 0,
    "inputs": [
      { "apiName": "leadId",                 "dataType": "id",        "isRequired": true,  "uiSection": "Lead",        "uiMode": "hidden", "targetObject": "Lead",        "targetFieldAPIName": "Id",     "sortOrder": 0 },
      { "apiName": "convertedStatus",        "dataType": "picklist",  "isRequired": true,  "uiSection": "Lead",        "uiMode": "hidden", "targetObject": "Lead",        "targetFieldAPIName": "Status", "requiredPicklistTag": "converted", "sortOrder": 1 },
      { "apiName": "accountId",              "dataType": "reference", "referenceTo": "Account",     "label": "Account",                  "uiSection": "Account",     "uiMode": "reuse",  "targetObject": "Account",                                                     "sortOrder": 2 },
      { "apiName": "contactFirstName",       "dataType": "string",                            "uiSection": "Contact",     "uiMode": "create", "targetObject": "Contact",     "targetFieldAPIName": "FirstName", "mappingSourceObject": "Lead", "mappingActionType": "convert", "sortOrder": 3 },
      { "apiName": "contactLastName",        "dataType": "string",                            "uiSection": "Contact",     "uiMode": "create", "targetObject": "Contact",     "targetFieldAPIName": "LastName",  "mappingSourceObject": "Lead", "mappingActionType": "convert", "sortOrder": 4 },
      { "apiName": "contactTitle",           "dataType": "string",                            "uiSection": "Contact",     "uiMode": "create", "targetObject": "Contact",     "targetFieldAPIName": "Title",     "mappingSourceObject": "Lead", "mappingActionType": "convert", "sortOrder": 5 },
      { "apiName": "contactEmail",           "dataType": "string",                            "uiSection": "Contact",     "uiMode": "create", "targetObject": "Contact",     "targetFieldAPIName": "Email",     "mappingSourceObject": "Lead", "mappingActionType": "convert", "sortOrder": 6 },
      { "apiName": "contactId",              "dataType": "reference", "referenceTo": "Contact",     "label": "Contact",                  "uiSection": "Contact",     "uiMode": "reuse",  "targetObject": "Contact",                                                     "sortOrder": 7 },
      { "apiName": "opportunityName",        "dataType": "string",                            "uiSection": "Opportunity", "uiMode": "create", "targetObject": "Opportunity", "targetFieldAPIName": "Name",      "mappingSourceObject": "Lead", "mappingActionType": "convert", "sortOrder": 8 },
      { "apiName": "opportunityId",          "dataType": "reference", "referenceTo": "Opportunity", "label": "Opportunity",              "uiSection": "Opportunity", "uiMode": "reuse",  "targetObject": "Opportunity",                                                 "sortOrder": 9 },
      { "apiName": "doNotCreateOpportunity", "dataType": "boolean",   "label": "Do Not Create Opportunity", "uiSection": "Opportunity", "uiMode": "skip",   "targetObject": "Opportunity",                                                 "sortOrder": 10 },
      { "apiName": "ownerId",                "dataType": "reference", "referenceTo": "User",        "label": "Owner",                    "uiSection": "Owner",       "uiMode": "reuse",  "targetObject": "User",                                                         "sortOrder": 11 },
      { "apiName": "overwriteLeadSource",    "dataType": "boolean",   "label": "Overwrite Lead Source",   "uiSection": "Contact",     "uiMode": "reuse",  "targetObject": "Contact",                                                     "sortOrder": 12 }
    ],
    "outputs": [
      { "apiName": "leadId",        "dataType": "id",        "sortOrder": 0 },
      { "apiName": "opportunityId",         "dataType": "reference", "referenceTo": "Opportunity", "sortOrder": 1 },
      { "apiName": "accountId",             "dataType": "reference", "referenceTo": "Account",     "sortOrder": 2 },
      { "apiName": "contactId",             "dataType": "reference", "referenceTo": "Contact",     "sortOrder": 3 },
      { "apiName": "opportunityCampaignId", "dataType": "reference", "referenceTo": "Campaign",    "label": "Campaign attribution", "uiSection": "Opportunity", "uiMode": "preview", "targetObject": "Opportunity", "targetFieldAPIName": "CampaignId", "sortOrder": 4 }
    ],
    "fieldDefaults": [
      {
        "targetObject": "Opportunity",
        "fieldAPIName": "CloseDate",
        "valueFormula": "TODAY() + 30",
        "priority": 0
      }
    ],
    "inputGuards": [
      {
        "condition": "true",
        "requiredObject": "Lead",
        "requiredOperation": "Edit",
        "errorMessage": "permission denied: Lead.Edit is required during lead convert",
        "sortOrder": 0
      },
      {
        "condition": "ISBLANK(Input.accountId)",
        "requiredObject": "Account",
        "requiredOperation": "Create",
        "errorMessage": "permission denied: Account.Create is required to create an Account during lead convert",
        "gatedInput": "accountId",
        "sortOrder": 10
      },
      {
        "condition": "NOT(ISBLANK(Input.accountId))",
        "requiredObject": "Account",
        "requiredOperation": "Read",
        "errorMessage": "permission denied: Account.Read is required to reuse an Account during lead convert",
        "gatedInput": "accountId",
        "sortOrder": 20
      },
      {
        "condition": "ISBLANK(Input.contactId)",
        "requiredObject": "Contact",
        "requiredOperation": "Create",
        "errorMessage": "permission denied: Contact.Create is required to create a Contact during lead convert",
        "gatedInput": "contactId",
        "sortOrder": 30
      },
      {
        "condition": "NOT(ISBLANK(Input.contactId))",
        "requiredObject": "Contact",
        "requiredOperation": "Edit",
        "errorMessage": "permission denied: Contact.Edit is required to reuse a Contact during lead convert",
        "gatedInput": "contactId",
        "sortOrder": 40
      },
      {
        "condition": "AND(Input.doNotCreateOpportunity != true, ISBLANK(Input.opportunityId))",
        "requiredObject": "Opportunity",
        "requiredOperation": "Create",
        "errorMessage": "permission denied: Opportunity.Create is required to create an Opportunity during lead convert",
        "gatedInput": "opportunityName",
        "sortOrder": 50
      },
      {
        "condition": "AND(Input.doNotCreateOpportunity != true, NOT(ISBLANK(Input.opportunityId)))",
        "requiredObject": "Opportunity",
        "requiredOperation": "Edit",
        "errorMessage": "permission denied: Opportunity.Edit is required to reuse an Opportunity during lead convert",
        "gatedInput": "opportunityId",
        "sortOrder": 60
      },
      {
        "condition": "Input.doNotCreateOpportunity == true",
        "requiredPermission": "SkipOpportunityOnConvert",
        "errorMessage": "permission denied: you do not have permission to skip opportunity creation during lead convert",
        "gatedInput": "doNotCreateOpportunity",
        "sortOrder": 70
      }
    ],
    "internalAccessScopes": [
      {
        "objectApiName": "FlowDefinition",
        "operation": "Read",
        "reason": "Lead Convert owns resolution of its pack-owned standard FlowDefinition after the caller has passed the ConvertLeads action gate."
      },
      {
        "objectApiName": "Flow",
        "operation": "Read",
        "reason": "Lead Convert owns resolution of its pack-owned active Flow version after the caller has passed the ConvertLeads action gate."
      },
      {
        "objectApiName": "OpportunityContactRole",
        "operation": "Read",
        "reason": "Lead Convert owns lookup of existing opportunity contact roles before promoting or creating the primary role."
      },
      {
        "objectApiName": "OpportunityContactRole",
        "operation": "Create",
        "reason": "Lead Convert owns creation of the primary opportunity contact role after conversion."
      },
      {
        "objectApiName": "OpportunityContactRole",
        "operation": "Edit",
        "reason": "Lead Convert owns demotion and promotion of primary opportunity contact roles after conversion."
      },
      {
        "objectApiName": "CampaignMember",
        "operation": "Read",
        "reason": "Lead Convert owns lookup of campaign memberships for primary campaign attribution and child relink after conversion."
      },
      {
        "objectApiName": "CampaignMember",
        "operation": "Edit",
        "reason": "Lead Convert owns reparenting campaign memberships from Lead to Contact after conversion."
      },
      {
        "objectApiName": "Task",
        "operation": "Read",
        "reason": "Lead Convert owns lookup of open tasks for child relink after conversion."
      },
      {
        "objectApiName": "Task",
        "operation": "Edit",
        "reason": "Lead Convert owns reparenting open tasks from Lead to converted Contact and Account or Opportunity."
      }
    ],
    "customPermissions": [
      {
        "apiName": "SkipOpportunityOnConvert",
        "label": "Skip Opportunity on Convert",
        "description": "Opt out of creating an Opportunity during Lead Convert. Seeded by the convertLead standard action; grant via permission sets."
      }
    ]
  }
]
