• Rajkumar CV 12
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hello All,

I have a List<SObject> which has various fields inside it. I need to get the value of one field inside the list and store it as a string.
The size of the list is 1 is all the cases.

List<SObject> values = UpdateActionMap.get(keyIteration);
String busiType = (String) values. ....... ?

Can anyone help me how to achieve this?
 
Below is my component
<aura:component controller="CSVController">
  <aura:handler name="init" value="{!this}" action="{!c.loadContactList}" />
  <aura:attribute name="listofContacts" type="Contact[]" />
  <div class="slds-m-around--xx-large">
    <button
      class="slds-button slds-button_brand"
      onclick="{!c.csvFileDownloader}"
    >
      Download as CSV
    </button>
    <br /><br />
    <table class="slds-table slds-table--bordered slds-table--cell-buffer">
      <thead>
        <tr class="slds-text-title--caps">
          <th class="slds-is-sortable slds-text-title--caps" scope="col">
            <span class="slds-truncate" title="Name">First Name</span>
          </th>

          <th class="slds-is-sortable slds-text-title--caps" scope="col">
            <span class="slds-truncate" title="Last Name">Last Name</span>
          </th>

          <th class="slds-is-sortable slds-text-title--caps" scope="col">
            <span class="slds-truncate" title="Department">Department</span>
          </th>

          <th scope="col">
            <div class="slds-truncate" title="MobilePhone">Mobile Phone</div>
          </th>
        </tr>
      </thead>
      <tbody>
        <aura:iteration items="{!v.listofContacts}" var="con">
          <tr>
            <th scope="row">
              <div class="slds-truncate" title="{!con.FirstName}">
                {!con.FirstName}
              </div>
            </th>
            <th scope="row">
              <div class="slds-truncate">
                {!con.LastName}
              </div>
            </th>
            <th scope="row">
              <div class="slds-truncate">
                {!con.Department}
              </div>
            </th>
            <th scope="row">
              <div class="slds-truncate">
                {!con.MobilePhone}
              </div>
            </th>
          </tr>
        </aura:iteration>
      </tbody>
    </table>
  </div>
</aura:component>
Below is my controller 
({
  loadContactList: function (component, event, helper) {
    helper.onLoad(component, event);
  },

  csvFileDownloader: function (component, event, helper) {
    console.log("Inside the controller method");
    var getContacts = component.get("v.listofContacts");
    console.log("controller " + getContacts);
    console.log(getContacts);

    var csvStringresult = helper.convertArrayofObjectstoCSV(
      component,
      getContacts
    );
    if (csvStringresult == null) {
      return null;
    }
    var anchorElement = document.createElement("a");
    anchorElement.href =
      "data:text/csv;charset=utf-8," + encodeURI(csvStringresult);
    anchorElement.target = "_self";
    anchorElement.download = "ExportData.csv";
    document.body.appendChild(anchorElement);
    anchorElement.click();
  }
});

Below is my helper
({
  onLoad: function (component, event) {
    var action = component.get("c.getContacts");
    action.setCallback(this, (response) => {
      var state = response.getState();
      if (state === "SUCCESS") {
        component.set("v.listofContacts", response.getReturnValue());
        var testing = component.get("v.listofContacts");
        console.log("raj" + testing);
      }
    });
    $A.enqueueAction(action);
  },

  convertArrayofObjectstoCSV: function (component, getContacts) {
    console.log("inside helper method");
    console.log(!getContacts.length);
    if (getContacts == null || !getContacts.length) {
      return null;
    }

    var columndivider = ",";
    var rowdivider = "\n";
    var keys = ["FirstName", "LastName", "Department", "MobileNumber"];
    var csvStringResult = " ";
    console.log(csvStringResult);
    csvStringResult += keys.join(columndivider);
    console.log(csvStringResult);
    csvStringResult += rowdivider;
    console.log(csvStringResult);

    for (var i = 0; i < getContacts.length; i++) {
      var counter = 0;

      for (var skey in keys) {
        console.log("skey " + skey);
        var newkey = keys[skey];
        console.log("newkey" + newkey);
        if (counter > 0) {
          csvStringResult += columndivider;
          console.log("1" + csvStringResult);
        }
        csvStringResult += '"' + getContacts[i][skey] + '"';
        console.log("2" + csvStringResult);
        counter++;
      }
      csvStringResult += rowdivider;
      console.log("3" + csvStringResult);
    }
    return csvStringResult;
  }
});

When i down​load the excel or view the console logs​​​​​​ i am getting undefined in the values field. Please let me know what may be the reason?

Thanks in advance.
Hello Everyone,
This is more kind of a dumb question. I have a requirement where we are integrating two Salesforce organisation. I refered a few articles regarding this and i found that everyone are creating a Connected App only on the Target side(meaning where to send my data).
So really wondering, do we always need to create a Connected App only on the receiving side? Or there are scenarios where you can create it in Source side also. If yes, please let me know.

Thanks in advance.

Regards,
Rajkumar CV
 
List<Case> localemailaddress = new List<Case>([SELECT ID,AV_Local_Affiliate_Inbox__c FROM Case Where Id IN : newCaseMap.keySet()]);
if(localemailaddress.size()>0 && localemailaddress!=null&&localemailaddress.get(0).AV_Local_Affiliate_Inbox__c!=null){
String affiliateemail=String.valueOf(localemailaddress.get(0).AV_Local_Affiliate_Inbox__c);

Please let me know it is very urgent.
List<Case> localemailaddress = new List<Case>([SELECT ID,AV_Local_Affiliate_Inbox__c FROM Case Where Id IN : newCaseMap.keySet()]);
if(localemailaddress.size()>0 && localemailaddress!=null&&localemailaddress.get(0).AV_Local_Affiliate_Inbox__c!=null){
String affiliateemail=String.valueOf(localemailaddress.get(0).AV_Local_Affiliate_Inbox__c);

Please let me know it is very urgent.