Trying to change the case owner of a specific case by changing the OwnerId value but I am not having any success.. I have compared my query with the docs and I can't understand why it's failing. The examples in the docs are for the Contact object, I could not find examples for Case object but thought it should be the same procedure.
Permissions should not be an issue as I can make updates via workbench on the same field without any problems, however, i'm trying to integrate this with php.
try {
$caseId = "5004z00001fqUIRAA2";
//query to target specific case to update
$query = "SELECT CaseNumber,Id,OwnerId FROM Case WHERE Id = '".$caseId."'";
$queryResponse = $mySforceConnection->query($query);
$queryResult = new QueryResult($queryResponse);
echo "<pre>",print_r($queryResult,true),"</pre>";
//prepare field update
$sObject = new SObject();
$sObject->type = 'Case';
$sObject->fields['OwnerId'] = "0054z000008RuHkAAK";
$sObject->Id = $caseId;
//submit update
$updateResponse = $mySforceConnection->update(array($sObject),'Case');
print_r($updateResponse);
} catch (Exception $e) {
echo $mySforceConnection->getLastRequest();
echo $e->faultstring;
}
Here is the response I get on the initial query to confirm I am getting a response back.
QueryResult Object
(
[queryLocator] =>
[done] => 1
[records] => Array
(
[0] => stdClass Object
(
[Id] => 5004z00001fqUIRAA2
[CaseNumber] => 03161663
[OwnerId] => 0054z000007HMzcAAG
)
)
[size] => 1
[pointer] => 0
[sf:QueryResult:private] =>
)
However, when performing the subsequent query to update the OwnerId value I get the following error:
INVALID_FIELD: No such column 'fields' on entity 'Case'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
The OwnerId field is not a custom field, it's standard field of the Case object. I even confirmed this field exists within the object.
Any Ideas?
Not much of an answer but too long for a comment.
https://barefoot.sourcerepo.com/barefoot/php_toolkit/trunk/php_toolkit/ looks very old, it references API versions ~20? SF API version is 55-56 now and in fact they plan to kill old versions: https://help.salesforce.com/s/articleView?language=en_US&id=000354473&type=1
Have you just grabbed that (old) sample code or have you downloaded the WSDL file from Salesforce and "consumed" it?
You're dumping the last request only in the catch block - what if you try to dump it anyway, similar to https://help.salesforce.com/s/articleView?id=000383659&type=1
The final XML should be similar to https://developer.salesforce.com/blogs/2015/06/salesforce-soap-api-sample-wsdls "Scenario 8: Updating the ownership of a record using the update() API." Which well, this blog post is from 2015, about 20 API versions old but it's something.
You could also import the WSDL to SoapUI, Postman or what-have-you and experiment with manual calling login, then update in there?
Related
I want to save the array to the database which the array is take from the DOMDocument I have created. I keep trying to save the array but it doesn't work. The database didn't show any data. Below is the function I have create.
public function actionGetLme()
{
$htmlContent = file_get_contents("https://www.lme.com/");
$DOM = new \DOMDocument();
#$DOM->loadHTML($htmlContent);
$headerDOM = $DOM->getElementsByTagName('th'); //Getting the header of the table
//#Get header name of the table
foreach($headerDOM as $nodeHeader)
{
$aDataTableHeaderHTML[] = trim($nodeHeader->textContent);
}
// print_r($aDataTableHeaderHTML);
$shifted = array_shift($aDataTableHeaderHTML);
//print_r($aDataTableHeaderHTML);
#Get row data/detail table without header name as key
$detailDOM = $DOM->getElementsByTagName('td');
foreach($detailDOM as $sNodeDetail) //Gettting the table data
{
$dataCell[] = trim($sNodeDetail->textContent);
}
// print_r($dataCell);
$mapping[$shifted]=array_combine($aDataTableHeaderHTML,$dataCell);
//print_r($mapping);
$model = new Lme();
$model->load(Yii::$app->request->post());
$model->lme_title = $shifted; // The data that I want to save to the db
$model->lme_name = $aDataTableHeaderHTML; // The data that I want to save to the db
$model->lme_price = $dataCell; // The data that I want to save to the db
$model->save();
The $shifted value is the top table header. Can refer to the link inside the code for more clearly understanding.
I already change the data to the array form. Below is the output of the DOMDocument which I get.
Array
(
[US$: 24 February 2020] => Array
(
[LME Aluminium] => 1,672.50
[LME Copper] => 5,657.50
[LME Zinc] => 2,039.00
[LME Nickel] => 12,360.00
[LME Lead] => 1,864.00
[LME Tin] => 16,510.00
[LME Aluminium Alloy] => 1,360.00
[LME NASAAC] => 1,260.00
[LME Cobalt] => 33,500.00
[LME Gold*] => 1,674.30
[LME Silver*] => 18.900
[LME Steel Scrap**] => 290.00
[LME Steel Rebar**] => 442.00
)
)
I have create the database table with the lme_id, lme_title, lme_name and lme_price. I want to save the $shifted to the lme_title, $aDataTableHeaderHtml to lme_name, and $dataCell to lme_price.
Example : |lme_id|lme_title|lme_name|lme_price|
| 1 | Title | Copper | 1660.00 |
Hope someone can teach me how to save the array into the database by using Yii2 framework.
Thanks.
I think you are missing something important like which database manager you are using, for example, MySQL, mssql, RDBMS.
But just to notice not many DBMS allows you to save an array directly into the database, cause normal data types to be stored in databases are practical primitive values.
So, If this is the case, you could apply to methods around this:
The first one is to use the PHP implode method to generate a string value which can then be saved into the database as you would do whit normal VARCHARS fields.
This method has some concerns which are by which I would not recommend this.
For example,
1- The complex string being formed is difficult to read.
2- You would end up needing to use a flag value to determinate the break and another value added to the array could cause problems with the flag you are using.
The second method, which is what I would recommend is to store as a JSON value.
Many DBMS support this type of data nowadays, and also it is a standardized format so what you could do in PHP is first to make a json_encode(YOUR_ARRAY) and then stored in the database.
json_encode docs
json_decode docs
I'm not sure about the Yii part cause I haven't used it for quite some time. But I hope this information can guide you.
I have been using a formula to uniquely secure id's gathered from database before they are presented to the client.
However, as my code grown complex, I've fallen into this pitfall: I have two separate cases returning json that need to use the same id. Because my securing function produces a unique hash and key at each perform, hashed ID gathered from one case cannot be encrypted in the other one that needs to use it. Therefore as a solution, I thought that sending hashed id gathered from first case back to first case again, decrypt it there and then somehow pass it to the other case without client never having chance to catch the real id.
All the codes work fine, my problem is matching the id drawn from first case that is to be used in the second case that also sends data back before case break, which is simply a client-triggered loop. I am providing codes in case you would ask it. The problem is simply matching the same id with different unique hash in two separate php cases. Sorry if I made this more complicated than it should have.
This is the first case I am using for filling a dropdown select.
case "tutorRefresh":
$tutorSelectSql = "SELECT id, tname, tsurname FROM tutors";
$tutorSelectQry = pg_query($tutorSelectSql);
while($row = pg_fetch_array($tutorSelectQry)){
$id = lockPandoraBox($row['id']);//encrypt the id
$response[] = array("id" => $id,
"tname" => $row['tname'],
"tsurname" => $row['tsurname']);
};
if(isset($response)){
echo json_encode($response);
} else {
$response = array("val" => 0);
echo json_encode($response);
}
break;
This is the function used by the second case that updates the table data, since it is too long and complex for a single issue to post it all here, I only shared relevant part of the code. I have to match the id encrypted in above code with the one encrypted here since this code fills in the table while the code above just fills in the dropdown select.
$crypted = lockPandoraBox($row["appid"]);
$tutorID = lockPandoraBox($row["tutorid"]);//encrypting id
$clientID = lockPandoraBox($row["clientid"]);//same method for another id, ignore this.
$fApp["hours"][] = array("recId" => $crypted,
"hour" => $row["hour"],
"tutor" => $tutorArr["tname"]." ".$tutorArr["tsurname"],
"tutorId" => $tutorID,// id that I need to use
"client" => $clientArr["cname"]." ".$clientArr["csurname"],
"clientId" => $clientID,
"department" => $dept,
"degree" => $deg,
"purpose" => $purposeArr["pname"],
"purposeId" => $row["purpose"],
"contact" => $clientArr["cgsm"],
"email" => $clientArr["cemail"],
"tutorAbsCheck" => $tutorAbsArray["id"],
"tutorAbsReason" => $tutorAbsArray["reason"],
"clientAbsCheck" => $clientAbsArray["id"],
"clientAbsReason" => $clientAbsArray["reason"]
);
/* */
}
return json_encode($fApp);
}
Lastly, this is the code in my main page which works in click event function that triggers the event I need. It simply changes select box's selection for the matching clicked record. It picks the id from table and tries to match it with the id in select box. Thanks in advance.
$("#tutorEdit").val(dayData["hours"][$(el.currentTarget).attr("key")].tutorId).trigger("change");
I think it will be better to change the structure a bit to combine both cases in order to achieve my goal. I wanted to know if I could get around it.
I'm new to PHP and I'm trying to modify my Wordpress-based Learning Management theme (called Academy on ThemeForest) to be able to work out which lesson in the current course the user is up to.
In other words, I want to run a check to see which lessons the user has completed, getting only the ID of the first lesson in the course hierarchy that has not been completed.
Here's everything I know:
Within the loop of a single post (in this case a "course"), this is how I get the array of the current course's lessons:
<?php $lessons_array = ThemexCourse::sortLessons(ThemexCourse::$data['course']['lessons']); ?>
This produces this nested array:
Array ( [0] => WP_Post Object ([ID] => 117 [menu_order]=>1) [1] => WP_Post Object ([ID] => 124 [menu_order]=>2) [2] => WP_Post Object ([ID] => 156 [menu_order]=>3))
I've truncated it a bit since the two values, [ID] and [menu_order], are the most important: they tell you the ID of each lesson and their hierarchy in the course.
But this is where I get stuck: I don't want to get all of the lesson IDs, just the one the user has yet to complete.
In order to check if a user has completed a lesson or not, I've been using this:
<?php if(ThemexCourse::isCompletedLesson($lesson_ID)) { echo 'Completed'; } ?>
So using the above information, is it possible to return a single ID of only the next incomplete lesson?
Thanks to anyone in advance for your help!
I think that should do it:
$next_lesson = NULL;
foreach($lessons_array as $index=>$lesson) {
if(!ThemexCourse::isCompletedLesson($lesson->ID)) {
$next_lesson = $lesson;
break;
}
}
echo "Next lesson is: " . $next_lesson->ID;
I have created a light Model Manager for LDAP over PHP's API to ease object managements from Active Directory.
Everything runs fine but I have a problem when updating multi valued attributes even if I change all the values, the transaction fails with «Type or value exists» error and the attribute is not changed in the database.
The test case I am using is to change de multi valued "description" field for a user. If I add new values or change the whole array of values, the transaction always fail.
The part of the code is the following:
if (count($mod_attr) > 0)
{
$ret = #ldap_mod_replace($this->getHandler(), $dn, $mod_attr);
if ($ret === false)
{ $this->log(sprintf("LDAP ERROR '%s' -- Modifying {%s}.", ldap_error($this->getHandler()), print_r($mod_attr, true)), \SlapOM\LoggerInterface::LOGLEVEL_CRITICAL);
throw new LdapException(sprintf("Error while MODIFYING values <pre>%s</pre> in dn='%s'.", print_r($mod_attr, true), $dn), $this->getHandler(), $this->error);
}
$this->log(sprintf("Changing attribute {%s}.", join(', ', array_keys($mod_attr))));
}
The complete code can be found [here on github](https://github.com/chanmix51/SlapOM/blob/master/lib/SlapOM/Connection.php#L115 [github]).
The logs show the following lines:
2013-06-04 10:39:54 | => MODIFY dn='CN=HUBERT Gregoire,OU=...
2013-06-04 10:39:54 | => LDAP ERROR 'Type or value exists' -- Modifying {Array
(
[description] => Array
(
[0] => Description 2
[1] => Description 3
)
)}
Even if the preceding values were ["description" => ['Description 1']]. Is there something I am not getting or doing wrong ?
The answer is short: «Description is not a multi valued field». As usual, the error message was so confusing, it lead me to spend hours on the wrong problem.
In short: the LDAP error 20 «Type or value exists» can be either you are trying to insert twice the same values in a multi valued field or you are trying to insert several values in a single valued field.
I'm able to query my dynamodb tables, but I only want to retrieve the actual value. I don't want the formatting output. This same question has been answered here for Java, but I'm looking for the PHP solution:
Retrieving just the item value from a dynamodb table?
Here is my getitem query:
$response = $dynamodb->getItem(array(
"TableName" => $tableName,
"ConsistentRead" => true,
"Key" => array(
"userguid" => array(Type::STRING => $userguid)
),
"AttributesToGet" => array("token")
));
print_r($response["Item"]["token"]);
Here is the output:
Array
(
[S] => 9d194513
)
All I want to get back is:
9d194513
I assumed the logical answer would be to change the last line to:
print_r($response["Item"]["token"]["S"]);
But then my code doesn't return anything at all. Obviously still learning PHP here, and any help would be appreciated.
Don't use print_r function, just either echo your variables
echo $response["Item"]["token"]["S"];
or store in a variable for later use
$res_token = $response["Item"]["token"]["S"];
You can also use the getPath convenience method built into the Model object that the SDK returns for operations.
echo $response->getPath('Item/token/S');
For more information about working with responses in the SDK, see the Response Models page in the AWS SDK for PHP User Guide.
Though it's an old question but for anyone coming to this page for seeking answer, this is how I have done it.
getItem returns a Resultobject. You can call the get() function of the SDK, which will give you an array containing the exact value.
$params = [
"TableName" => "EpgApiAccessCount",
"Key" => $this->marshalJson('
{
"ApiUserKey": "' . $apiUserkey . '"
}
')
];
$result = $this->client->getitem($params);
if (!$result instanceof ResultInterface) {
return 0;
}
$item = $this->unmarshalItem($result->get("Item"));
return $item["AccessCount"];
Of course your value and table name will be different, and you can print or do anything else with the value.