Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightningComponentBundle (LWC): reading/creating/updating #293

Open
lukethacoder opened this issue Apr 16, 2023 · 0 comments
Open

LightningComponentBundle (LWC): reading/creating/updating #293

lukethacoder opened this issue Apr 16, 2023 · 0 comments

Comments

@lukethacoder
Copy link

Struggling to get LWC reading/creating/updating working properly.

Current WSDL Generated Apex

Auto generated from the Metadata WSDL export, and then the Generate Apex from WSLD.

public class LightningComponentBundle extends Metadata {
  public String type = 'LightningComponentBundle';
  public String fullName;
  private String[] fullName_type_info = new String[]{'fullName',SOAP_M_URI,null,'0','1','false'};
  public Double apiVersion;
  public MetadataService.Capabilities capabilities;
  public String description;
  public Boolean isExplicitImport;
  public Boolean isExposed;
  public MetadataService.LwcResources lwcResources;
  public String masterLabel;
  public String runtimeNamespace;
  public String targetConfigs;
  public MetadataService.Targets targets;
  private String[] apiVersion_type_info = new String[]{'apiVersion',SOAP_M_URI,null,'0','1','false'};
  private String[] capabilities_type_info = new String[]{'capabilities',SOAP_M_URI,null,'0','1','false'};
  private String[] description_type_info = new String[]{'description',SOAP_M_URI,null,'0','1','false'};
  private String[] isExplicitImport_type_info = new String[]{'isExplicitImport',SOAP_M_URI,null,'0','1','false'};
  private String[] isExposed_type_info = new String[]{'isExposed',SOAP_M_URI,null,'0','1','false'};
  private String[] lwcResources_type_info = new String[]{'lwcResources',SOAP_M_URI,null,'0','1','false'};
  private String[] masterLabel_type_info = new String[]{'masterLabel',SOAP_M_URI,null,'0','1','false'};
  private String[] runtimeNamespace_type_info = new String[]{'runtimeNamespace',SOAP_M_URI,null,'0','1','false'};
  private String[] targetConfigs_type_info = new String[]{'targetConfigs',SOAP_M_URI,null,'0','1','false'};
  private String[] targets_type_info = new String[]{'targets',SOAP_M_URI,null,'0','1','false'};
  private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
  private String[] field_order_type_info = new String[]{'fullName','apiVersion','capabilities','description','isExplicitImport','isExposed','lwcResources','masterLabel','runtimeNamespace','targetConfigs','targets'};
}
public class Capabilities {
  public String[] capability;
  private String[] capability_type_info = new String[]{'capability',SOAP_M_URI,null,'0','-1','false'};
  private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
  private String[] field_order_type_info = new String[]{'capability'};
}
public class LwcResources {
  public String type = 'LwcResources';
  public MetadataService.LwcResource[] lwcResource;
  private String[] lwcResource_type_info = new String[]{'lwcResource',SOAP_M_URI,null,'0','-1','false'};
  private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
  private String[] field_order_type_info = new String[]{'lwcResource'};
}
public class LwcResource {
  public String type = 'LwcResource';
  public String filePath;
  public String source;
  private String[] filePath_type_info = new String[]{'filePath',SOAP_M_URI,null,'1','1','false'};
  private String[] source_type_info = new String[]{'source',SOAP_M_URI,null,'1','1','false'};
  private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
  private String[] field_order_type_info = new String[]{'filePath','source'};
}
public class Targets {
  public String[] target;
  private String[] target_type_info = new String[]{'target',SOAP_M_URI,null,'0','-1','false'};
  private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
  private String[] field_order_type_info = new String[]{'target'};
}

Noticed the AuraDefinitionBundle has some extra read methods, so attempted to duplicate them for LWCs too, but am still running into issues. Also added extends Metadata too.

public class ReadLightningComponentBundleResult implements IReadResult {
  public MetadataService.LightningComponentBundle[] records;
  public MetadataService.Metadata[] getRecords() { return records; }
  private String[] records_type_info = new String[]{'records',SOAP_M_URI,null,'0','-1','false'};
  private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
  private String[] field_order_type_info = new String[]{'records'};
}
public class readLightningComponentBundleResponse_element implements IReadResponseElement {
  public MetadataService.ReadLightningComponentBundleResult result;
  public IReadResult getResult() { return result; }
  private String[] result_type_info = new String[]{'result',SOAP_M_URI,null,'1','1','false'};
  private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
  private String[] field_order_type_info = new String[]{'result'};
}

Current Output

Here is the output I have so far. It looks to be retrieving the top-level metadata without any issues (except the targets/targetConfigs).

masterLabel, isExposed, fullName, description and apiVersion are all populated as expected, but the lwcResources is empty. Which I'm expecting to have an array of the files that make up the LWC (.js, .html and/or .css).

// anon apex code to test the method
MetadataService.IReadResult readNewLwcMagic() {
  MetadataService.MetadataPort service = createService();
  return service.readMetadata('LightningComponentBundle', new String[]{'dynamicLwcTest'});
}
MetadataService.MetadataPort createService() {
  MetadataService.MetadataPort service = new MetadataService.MetadataPort();
  service.SessionHeader = new MetadataService.SessionHeader_element();
  service.SessionHeader.sessionId = UserInfo.getSessionId();
  return service;
}

MetadataService.IReadResult resultRead = readNewLwcMagic();
MetadataService.Metadata[] records = resultRead.getRecords();
for (MetadataService.Metadata recordResult : records) {
  System.debug('recordResult:');
  System.debug(JSON.serialize(recordResult));
}
{
  "fullName": null,
  "type": "LightningComponentBundle",
  "targets_type_info": ["targets", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "targets": null,
  "targetConfigs_type_info": ["targetConfigs", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "targetConfigs": null,
  "runtimeNamespace_type_info": ["runtimeNamespace", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "runtimeNamespace": null,
  "masterLabel_type_info": ["masterLabel", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "masterLabel": "Dynamic Lwc Test",
  "lwcResources_type_info": ["lwcResources", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "lwcResources": null,
  "isExposed_type_info": ["isExposed", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "isExposed": true,
  "isExplicitImport_type_info": ["isExplicitImport", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "isExplicitImport": false,
  "fullName_type_info": ["fullName", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "fullName": "dynamicLwcTest",
  "field_order_type_info": [
    "fullName",
    "apiVersion",
    "capabilities",
    "description",
    "isExplicitImport",
    "isExposed",
    "lwcResources",
    "masterLabel",
    "runtimeNamespace",
    "targetConfigs",
    "targets"
  ],
  "description_type_info": ["description", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "description": "test LWC description here",
  "capabilities_type_info": ["capabilities", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "capabilities": null,
  "apiVersion_type_info": ["apiVersion", "http://soap.sforce.com/2006/04/metadata", null, "0", "1", "false"],
  "apiVersion": 57.0,
  "apex_schema_type_info": ["http://soap.sforce.com/2006/04/metadata", "true", "false"]
}

LightningComponentBundle does look to be supported by the SOAP API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant