function perform() { WorkbenchContext::get()->getApexConnection()->setDebugLevels($this->logCategory, $this->logCategoryLevel); $executeAnonymousResultWithDebugLog = WorkbenchContext::get()->getApexConnection()->executeAnonymous($this->executeAnonymousBlock); ob_start(); if ($executeAnonymousResultWithDebugLog->executeAnonymousResult->success) { if (isset($executeAnonymousResultWithDebugLog->debugLog) && $executeAnonymousResultWithDebugLog->debugLog != "") { print "<pre>" . addLinksToIds(htmlspecialchars($executeAnonymousResultWithDebugLog->debugLog, ENT_QUOTES)) . '</pre>'; } else { displayInfo("Execution was successful, but returned no results. Confirm log category and level."); } } else { $error = null; if (isset($executeAnonymousResultWithDebugLog->executeAnonymousResult->compileProblem)) { $error .= "COMPILE ERROR: " . $executeAnonymousResultWithDebugLog->executeAnonymousResult->compileProblem; } if (isset($executeAnonymousResultWithDebugLog->executeAnonymousResult->exceptionMessage)) { $error .= "\nEXCEPTION: " . $executeAnonymousResultWithDebugLog->executeAnonymousResult->exceptionMessage; } if (isset($executeAnonymousResultWithDebugLog->executeAnonymousResult->exceptionStackTrace)) { $error .= "\nSTACKTRACE: " . $executeAnonymousResultWithDebugLog->executeAnonymousResult->exceptionStackTrace; } if (isset($executeAnonymousResultWithDebugLog->executeAnonymousResult->line)) { $error .= "\nLINE: " . $executeAnonymousResultWithDebugLog->executeAnonymousResult->line; } if (isset($executeAnonymousResultWithDebugLog->executeAnonymousResult->column)) { $error .= " COLUMN: " . $executeAnonymousResultWithDebugLog->executeAnonymousResult->column; } displayError($error); print '<pre style="color: red;">' . addLinksToIds(htmlspecialchars($executeAnonymousResultWithDebugLog->debugLog, ENT_QUOTES)) . '</pre>'; } $result = ob_get_contents(); ob_end_clean(); return $result; }
private function printNode($node, $parentKey = null) { $systemFields = array("Id", "IsDeleted", "CreatedById", "CreatedDate", "LastModifiedById", "LastModifiedDate", "SystemModstamp"); // TODO: remove this hacky special casing $escape = !($this->name == "listMetadataTree" && ($parentKey == "parentXmlName" || $parentKey == "childXmlNames")); foreach ($node as $nodeKey => $nodeValue) { $nodeKey = $escape ? htmlspecialchars($nodeKey) : $nodeKey; // TODO: replace special case with client defined strategies if ($this->name == "describeTree") { if (isset($parentKey) && strpos($parentKey, "Fields") > -1) { if (in_array($nodeKey, $systemFields)) { $nodeKey = "<span class='highlightSystemField'>{$nodeKey}</span>"; } else { if (substr_compare($nodeKey, "__c", -3) == 0) { $nodeKey = "<span class='highlightCustomField'>{$nodeKey}</span>"; } } } } if (is_array($nodeValue) || is_object($nodeValue)) { if (is_numeric($nodeKey)) { $nodeKey = $nodeKey + 1; } print "<li>{$nodeKey}<ul style='display:none;'>\n"; if (is_array($nodeValue) && count($nodeValue) == 1 && isset($nodeValue[0]) && is_array($nodeValue[0])) { $this->printNode($nodeValue[0], $nodeKey); // flatten single element arrays } else { $this->printNode($nodeValue, $nodeKey); } print "</ul></li>\n"; } else { $nodeKey = is_numeric($nodeKey) ? "" : $nodeKey . ": "; if (is_bool($nodeValue)) { $nodeValue = $nodeValue == 1 ? "<span class='trueColor'>true</span>" : "<span class='falseColor'>false</span>"; } else { $nodeValue = $escape ? htmlspecialchars($nodeValue) : $nodeValue; $nodeValue = $this->containsDates ? localizeDateTimes($nodeValue) : $nodeValue; $nodeValue = $this->containsIds ? addLinksToIds($nodeValue) : $nodeValue; } print "<li>{$nodeKey}<span style='font-weight:bold;'>{$nodeValue}</span></li>\n"; } } }
/** * Display the PUT results from all synchronous * functions. * * @param $results * @param $apiCall * @param $csvArray * @param $idArray */ function displayIdOnlyPutResults($results, $apiCall, $csvArray, $idArray) { //check if only result is returned if (!is_array($results)) { $results = array($results); } unset($_SESSION['resultsWithData']); $resultsWithData = array(); //create array to hold results with data for download later $_SESSION['resultsWithData'][0] = array("Salesforce Id", "Result", "Status"); $_SESSION['resultsWithData'][0] = array_merge($_SESSION['resultsWithData'][0], $csvArray[0]); $successCount = 0; $errorCount = 0; ob_start(); for ($row = 0; $row < count($results); $row++) { $excelRow = $row + 1; $_SESSION['resultsWithData'][$row + 1] = array(); //create array for row if ($results[$row]->success) { $successCount++; print "<tr>"; print "<td>" . $excelRow . "</td>"; print "<td>" . addLinksToIds($results[$row]->id) . "</td>"; $_SESSION['resultsWithData'][$row + 1][0] = $results[$row]->id; print "<td>Success</td>"; $_SESSION['resultsWithData'][$row + 1][1] = "Success"; if ($apiCall == 'upsert' && $results[$row]->created || $apiCall == 'create') { print "<td>Created</td>"; $_SESSION['resultsWithData'][$row + 1][2] = "Created"; } else { if ($apiCall == 'upsert' && !$results[$row]->created || $apiCall == 'update') { print "<td>Updated</td>"; $_SESSION['resultsWithData'][$row + 1][2] = "Updated"; } else { if ($apiCall == 'delete' || $apiCall == 'undelete') { print "<td>" . ucwords($apiCall) . "d </td>"; $_SESSION['resultsWithData'][$row + 1][2] = ucwords($apiCall) . "d"; } else { if ($apiCall == 'emptyRecycleBin') { print "<td>Purged</td>"; $_SESSION['resultsWithData'][$row + 1][2] = "Purged"; } } } } print "</tr>\n"; } else { $errorCount++; print "<tr style='color: red;'>"; print "<td>" . $excelRow . "</td>"; if (!isset($results[$row]->id) && isset($idArray)) { $_SESSION['resultsWithData'][$row + 1][0] = $idArray[$row]; //add id from idArray for id-only calls print "<td>" . addLinksToIds(htmlspecialchars($idArray[$row])) . "</td>"; } else { $_SESSION['resultsWithData'][$row + 1][0] = $results[$row]->id; //add id from results for everything else print "<td>" . addLinksToIds(htmlspecialchars($results[$row]->id)) . "</td>"; } $errMsgs = ""; $statusCodes = ""; if (is_array($results[$row]->errors)) { $errMsgs = implode("; ", array_map("extractMessage", $results[$row]->errors)); $statusCodes = implode("; ", array_map("extractStatusCode", $results[$row]->errors)); } else { $errMsgs .= $results[$row]->errors->message; $statusCodes .= $results[$row]->errors->statusCode; } print "<td>" . ucwords($errMsgs) . "</td>"; $_SESSION['resultsWithData'][$row + 1][1] = ucwords($errMsgs); print "<td>" . $statusCodes . "</td>"; $_SESSION['resultsWithData'][$row + 1][2] = $statusCodes; print "</tr>\n"; } $_SESSION['resultsWithData'][$row + 1] = array_merge($_SESSION['resultsWithData'][$row + 1], $csvArray[$row + 1]); } print "</table><br/>"; $resultsTable = ob_get_clean(); displayInfo("There " . ($successCount == 1 ? "was" : "were") . " {$successCount} success" . ($successCount == 1 ? "" : "es") . " and {$errorCount} error" . ($errorCount == 1 ? "" : "s")); print "<br/><form action='downloadResultsWithData.php' method='GET'><input type='hidden' name='action' value='{$apiCall}'/><input type='submit' value='Download Full Results'/></form>"; print "<br/>\n<table class='dataTable'>\n"; print "<th> </th> <th style='width: 30%'>Salesforce Id</th> <th style='width: 30%'>Result</th> <th style='width: 35%'>Status</th>\n"; print "<p>{$resultsTable}</p>"; }
function displayQueryResults($records, $queryTimeElapsed, QueryRequest $queryRequest) { if (is_numeric($records)) { $countString = "Query would return {$records} record"; $countString .= $records == 1 ? "." : "s."; displayInfo($countString); return; } if (!$records) { displayWarning("Sorry, no records returned."); return; } if (WorkbenchConfig::get()->value("areTablesSortable")) { addFooterScript("<script type='text/javascript' src='" . getPathToStaticResource('/script/sortable.js') . "></script>"); } print "<a name='qr'></a><div style='clear: both;'><br/><h2>Query Results</h2>\n"; if (isset($this->queryLocator)) { preg_match("/-(\\d+)/", $this->queryLocator, $lastRecord); $rowOffset = $lastRecord[1]; } else { $rowOffset = 0; } $minRowNum = $rowOffset + 1; $maxRowNum = $rowOffset + count($records); print "<p>Returned records {$minRowNum} - {$maxRowNum} of " . $this->totalQuerySize . " total record" . ($this->totalQuerySize !== 1 ? "s" : "") . " in " . sprintf("%01.3f", $queryTimeElapsed) . " seconds:</p>\n"; if (!WorkbenchConfig::get()->value("autoRunQueryMore") && $this->nextQueryLocator) { print "<p><input type='hidden' name='queryLocator' value='" . $this->nextQueryLocator . "' /></p>\n"; print "<p><input type='submit' name='queryMore' id='queryMoreButtonTop' value='More...' /></p>\n"; } print addLinksToIds($queryRequest->getExportTo() == 'matrix' ? $this->createQueryResultsMatrix($records, $queryRequest->getMatrixCols(), $queryRequest->getMatrixRows()) : $this->createQueryResultTable($records, $minRowNum)); if (!WorkbenchConfig::get()->value("autoRunQueryMore") && $this->nextQueryLocator) { print "<p><input type='hidden' name='queryLocator' value='" . $this->nextQueryLocator . "' /></p>\n"; print "<p><input type='submit' name='queryMore' id='queryMoreButtonBottom' value='More...' /></p>"; } print "</form></div>\n"; }
unset($results->retrieveResult->zipFile); } } displayInfo("Retrieve result ZIP file is ready for download."); print "<p/>"; $zipLink = " | <a id='zipLink' href='?asyncProcessId={$asyncResults->id}&downloadZip' onclick='undownloadedZip=false;' style='text-decoration:none;'>" . "<span style='text-decoration:underline;'>Download ZIP File</span> <img src='" . getPathToStaticResource('/images/downloadIconCompleted.gif') . "' border='0'/>" . "</a></p>"; } $tree = new ExpandableTree("metadataStatusResultsTree", ExpandableTree::processResults($results)); $tree->setForceCollapse(true); $tree->setAdditionalMenus($zipLink); $tree->setContainsIds(true); $tree->setContainsDates(true); $tree->printTree(); if (isset($debugInfo["DebuggingInfo"]->debugLog)) { print "<p> </p><h3>Debug Logs</h3>"; print "<pre>" . addLinksToIds(htmlspecialchars($debugInfo["DebuggingInfo"]->debugLog, ENT_QUOTES)) . '</pre>'; } // if metadata changes were deployed, clear the cache because describe results will probably be different if ($operation == "D") { WorkbenchContext::get()->clearCache(); } } } catch (Exception $e) { displayError($e->getMessage(), false, true); } ?> <script> var undownloadedZip = false; window.onbeforeunload = function() { if (undownloadedZip) { return 'There is a ZIP file awaiting download. It will be deleted if you refresh or navigate away from this page.';
function displaySearchResult($records, $searchTimeElapsed) { //Check if records were returned if ($records) { if (WorkbenchConfig::get()->value("areTablesSortable")) { addFooterScript("<script type='text/javascript' src='" . getPathToStaticResource('/script/sortable.js') . "></script>"); } try { print "<a name='sr'></a><div style='clear: both;'><br/><h2>Search Results</h2>\n"; print "<p>Returned " . count($records) . " total record"; if (count($records) !== 1) { print 's'; } print " in "; printf("%01.3f", $searchTimeElapsed); print " seconds:</p>"; $searchResultArray = array(); foreach ($records as $record) { $recordObject = new Sobject($record->record); $searchResultArray[$recordObject->type][] = $recordObject; } foreach ($searchResultArray as $recordSetName => $records) { echo "<h3>{$recordSetName}</h3>"; print "<table id='" . $recordSetName . "_results' class='" . getTableClass() . "'>\n"; //Print the header row on screen $record0 = $records[0]; print "<tr><th></th>"; //If the user queried for the Salesforce ID, this special method is nessisary //to export it from the nested SOAP message. This will always be displayed //in the first column regardless of search order if (isset($record0->Id)) { print "<th>Id</th>"; } if ($record0->fields) { foreach ($record0->fields->children() as $field) { print "<th>"; print htmlspecialchars($field->getName(), ENT_QUOTES); print "</th>"; } } else { print "</td></tr>"; } print "</tr>\n"; //Print the remaining rows in the body $rowNum = 1; foreach ($records as $record) { print "<tr><td>{$rowNum}</td>"; $rowNum++; //Another check if there are ID columns in the body if (isset($record->Id)) { print "<td>" . addLinksToIds($record->Id) . "</td>"; } //Print the non-ID fields if (isset($record->fields)) { foreach ($record->fields as $datum) { print "<td>"; if ($datum) { print localizeDateTimes(addLinksToIds(htmlspecialchars($datum, ENT_QUOTES))); } else { print " "; } print "</td>"; } print "</tr>\n"; } else { print "</td></tr>\n"; } } print "</table> <p/>"; } print "</div>\n"; } catch (Exception $e) { $errors = null; $errors = $e->getMessage(); print "<p />"; displayError($errors, false, true); } } else { print "<p><a name='sr'> </a></p>"; displayError("Sorry, no records returned."); } include_once 'footer.php'; }