I am looking for a way to mass update case Status and leave a success message or failure message with failed case ID.
I currently have validation rules and triggers for update or cases. But I need to keep show at least the first failed case ID in the error message.
Is there a way to put a variable in the validation rule error message? Or its explicitly string?
I currently use a validation rule but I cant show the failed case in my error message because I cant put a variable in the error message.
Check this Link it might help you http://appexchange.salesforce.com/listingDetail?listingId=a0N30000003IleFEAS
You need to use a before trigger in this case and compare the list of selected cases before and after the update.
Or you can create a custom button and add it to the page and run the desired javascript to check what changed before and after.
something like this :
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var idArray = {!GETRECORDIDS($ObjectType.Case)};
var err = [];
var caseObj;
for (i=0; i< idArray.length ; i++){
caseObj = new sforce.SObject("Case");
caseObj.Id = idArray[i];
caseObj.Status = *** //change status here;
var result = sforce.connection.update([caseObj]);
if (result[0].success=='false') {
err.push("\n"+result[0].errors.message + " Case ID "+idArray[i]);
}
}
if(err.length >0)
{
alert(" The following cases have failed to change status: \n\n" +err);
}
location.reload(true);
Related
I'm trying to use crossmint button in my react frontend to enable credit card payments, but I don't know what's wrong with my implementaton, I get this error:
"An error has occurred
Try again later. If the error persists contact us at crossmint.io/help"
error img
From the frontend this is what I have:
<CrossmintPayButton
clientId="028123eb-26ca-4a4e-9b80-02bd5719eb2e"
mintConfig={{
type: "erc-721",
totalPrice: "70",
_mintAmount: "1",
}}
mintTo={walletConnected}
environment="staging"
/>
You can take a look at the smart contract here in mumbai testnet:
https://mumbai.polygonscan.com/address/0x3503A639fFB7784836069DCa703057966729abbE#readContract
The function which must be called is this one:
function crossmint(address _to, uint256 _mintAmount) external payable {
uint256 totalSupply = totalSupply();
if (msg.sender != crossmintAddress) revert crossmintErr();
if (getWhitelistOn()) require(isWhitelisted[_to] || _to == owner());
if (paused && _to != owner()) revert pausedErr();
if (_mintAmount <= 0 || _mintAmount > maxMintAmount) revert mintAmountErr();
if (totalSupply + _mintAmount > maxSupply[mintPhase]) revert totalSupplyErr();
uint256 payAmount = getMintPayAmount(_to, _mintAmount, cost[mintPhase]);
if (_to != owner() && msg.value < payAmount.getConversionRate(priceFeed))
revert payAmountErr();
unchecked {
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(_to, totalSupply + i);
emit NftMinted(totalSupply + i, _to);
}
}
}
This crossmint function is equal to the mint function which works perfect, but checks msg.seder to be equal to crossmintAddress.
I double checked that crossmintAddress is set to "0xDa30ee0788276c093e686780C25f6C9431027234" as specified in the docs. What is interesting to me is that as you can see in the error, totalPrice is empty in th UI, but I can't find the error.
Any help with this is really appreciated.
UPDATE:
I found out that the parameter mintTo was receiving a wrong value and not the actual recipient address.
After changing that, I get a revert message
Contract error: execution reverted, no custom error mapping or message
found, contact Crossmint support to set up error mapping
revert error
So my question is:
is it possible that the transaction is reverted because it doesn't read the totalPrice correctly? On the transaction preview totalPrice seems to be empty.
I cannot update update this Boolean value in Apex. What is going wrong? The if statement, and the fact that the front end representation is a checkbox, proves that it is indeed a boolean value. I am new to Apex so I feel its a basic misunderstanding of how it works. Can anyone help me out?
Here is the code that I'm executing in an Anonymous Window.
Account acc = new Account(Name='Test Name');
if (acc.Do_Not_Contact__pc == false) {
System.debug('DNC is false');
} else {
System.debug('DNC is true');
}
insert acc;
acc.Do_Not_Contact__pc = true;
update acc;
It fails on the second to last line, displaying the following message:
System.DmlException: Update failed. First exception on row 0 with id 001W000000fFiVbIAK; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: Do_Not_Contact__pc: [Do_Not_Contact__pc]
What's particularly frustrating is that when I change the second to last line to
acc.Do_Not_Contact__pc = 'true';
I get an error stating that I cannot assign a String to a Boolean value
Remove the single quotes and I assume you typed the field name wrong. Try acc.Do_Not_Contact__c = true;
So my question is: how do I scan the JSON in angular to find the first instance of isPrimary:true and then launch a function with the GUID that is in that item.
I have a webservice whos JSON defines available Accounts with a display name and a GUID this generates a dropdown select list that calls a function with the GUID included to return full data from a web service.
In the scenario where theres only 1 OPTION I dont show the SELECT and simply call the function with the single GUID to return the data from the service. If theres no options I dont show anything other than a message.
Code below shows what I currently have.
The Spec has now changed and the data they are sending me in the first service call which defines that select list is now including a property isPrimary:true on one of the JSON object along with its GUID as per the rest
I now need to change my interface to no longer use the SELECT list and instead fire the function call to the service for the item that contains the isPrimary:true property. However there may be multiple instances where isPrimary:true exists in the returning JSON so I just want to fire the function on the first found instance of isPrimary:true
Equally if that property isnt in any of the JSON items then just fire the function on the first item in the JSON.
My current Code is below - you can see the call to retrieve the full details is from function:
vm.retrieveAccount(GUID);
Where the GUID is supplied with each JSON object
Code is:
if (data.Accounts.length > 1) {
vm.hideAcc = false;
setBusyState(false);
//wait for the user to make a selection
} else if (data.Accounts.length == 1){
vm.hideAcc = true;
// Only 1 acc - no need for drop down get first item
vm.accSelected = data.Accounts[0].UniqueIdentifier;
vm.retrieveAccount(vm.accSelected);
} else {
// Theres no accounts
// Hide Drop down and show message
setBusyState(false);
vm.hideAcc = true;
setMessageState(false, true, "There are no Accounts")
}
Sample of new JSON structure
accName: "My Acc",
isPrimary: true,
GUID: "bg111010101"
Still think that's a weird spec, but simple enough to solve. Just step through the array and return the first isPrimary match. If none are found, return the first element of the array.
var findPrimary = function(data) {
if (!(Array.isArray(data)) || data.length == 0) {
return false; // not an array, or empty array
}
for (var i=0; i<data.length; i++) {
if (data[i].isPrimary) {
return data[i]; // first isPrimary match
}
}
// nothing had isPrimary, so return the first one:
return data[0];
}
Problem
Calling repeater('#myTable tr','Rows').count(); returns a Future, not an integer. I need to get the integer value so I can confirm that an additional row was added to a table.
Code
it('should add a new user when save button is clicked',function()
{
showModal();
//here I'm trynig to store the row count of my table into a local variable.
//a future is returned who's 'value' field is undefined.
var memberCount = repeater('#memberTable tr','Member Rows').count();
//this outputs 'undefined'
console.log(memberCount.value);
input('editedMember.name').enter('John');
input('editedMember.grade').enter(5);
input('editedMember.ladderPosition').enter(3);
element('#saveMemberButton').click();
sleep(1);
expect(element(modalId).css('display')).toBe('none');
//here is where I want to do the comparison against the above stored memberCount
expect(repeater('#memberTable tr', 'Member Rows').count()).toBe(memberCount.value + 1);
});
Test Result
Chrome 25.0 e2e should add a new user when save button is clicked FAILED
expect repeater 'Member Rows ( #memberTable tr )' count toBe null
/Users/jgordon/learning/chessClub/web-app/test/e2e/scenarios.js:45:3: expected null but was 6
Chrome 25.0: Executed 2 of 2 (1 FAILED) (1 min 4.117 secs / 1 min 3.773 secs)
Drilling into the source code for Angularjs' e2e support reveals that you have to call execute() on the Future to have it populate its value. Also, when you call execute you have to provide a "done" function to the execute() otherwise Testacular will (oddly enough!) skip your test.
Code
var rowCountFuture = repeater('#memberTable tr','Member Rows').count();
rowCountFuture.execute(function(){
});
var memberCount = rowCountFuture.value;
While I'm jazzed to see this works, I'm concerned there may be some asynchronous bugs that could come out of this, also, I feel like this is a hack and not the right way to do it. Any ideas?
Based on the latest Protractor version:
it('should add a new user when save button is clicked', function() {
var memberCount;
element.all(by.repeater('#memberTable tr','Member Rows')).count().then(function(value) {
memberCount = value;
});
...
// then do all your entering user info, saving etc.
...
browser.refresh(); // or however you want to load new data
expect(element.all(by.repeater('#memberTable tr','Member Rows')).count()).toEqual(memberCount + 1);
});
I've run into the same issue, and have seen confusing results when testing value returned after calling execute(). I've found this method works more reliably:
var getCount = repeater('ul li').count();
getCount.execute(function(value) {
expect(value).toEqual(3);
});
You can do this most easily in the async promise returned by the locator
element.all(By.repeater 'thing in things').then(function(elements){
count = elements.length;
expect(count).toEqual(3);
});
Background
I have a list of sObjects I need to insert, but I must first check if the insert will be successful. So, I'm setting a database save point before performing the insert and checking the save results (for the insert statement). Because, I don't want to process if any errors occurred, if there were any errors in the insert results, the database is rolled back to the save point.
Problem & Question
I need to collect the errors for each save (insert) result and associate each error to the specific sObject record that caused the error. According to the documentation Save results contain a list of errors, the Salesforce ID of the record inserted (if successful), and a success indicator (boolean).
How do I associate the Save Result to the original sObject record inserted?
Code/Example
Here's an example I put together that demonstrates the concept. The example is flawed, in that the InsertResults don't always match the sObjectsToInsert. It's not exactly the code I'm using in my custom class, but it uses the same logic.
Map<Id,sObject> sObjectsToInsert; // this variable is set previously in the code
List<Database.SaveResult> InsertResults;
Map<String,sObject> ErrorMessages = new Map<String,sObject>();
System.SavePoint sp = Database.setSavepoint();
// 2nd parameter must be false to get all errors, if there are errors
// (allow partial successes)
InsertResults = Database.insert(sObjectsToInsert.values(), false);
for(Integer i=0; i < InsertResults.size(); i++)
{
// This method does not guarantee the save result (ir) matches the sObject
// I need to make sure the insert result matches
Database.SaveResult ir = InsertResults[i];
sObject s = sObjectsToInsert.values()[i];
String em = null; // error message
Integer e = 0; // errors
if(!ir.isSuccess())
{
system.debug('Not Successful');
e++;
for(Database.Error dbe : ir.getErrors()) { em += dbe.getMessage()+' '; }
ErrorMessages.put(em, s);
}
}
if(e > 0)
{
database.rollback(sp);
// log all errors in the ErrorMessages Map
}
Your comment says the SaveResult list is not guaranteed to be in order, but I believe that it is. I've used this technique for years and have never had an issue.