If any error occurred in salesforce site it show line number with class name (please refer below image) which we don't want to show to user.
Instead I want to display custom page in which details like class name, line number will be saved in object or send it via email to developer.
For security reason we want to hide details from user. Even I did not found any option In Site-> "Error Pages" to add custom page for apex error.
You can have a try catch block for your code where you think exception can occur.
For getting stack trace of the error log with class name and line number's we have a method called getStackTraceString().This method returns the stack trace of the error as a string.
Example:
try {
Merchandise__c m = [
SELECT Name
, Total_Inventory__c
FROM Merchandise__c
LIMIT 1
];
Double inventory = m.Total_Inventory__c;
} catch(Exception e) {
System.debug('Exception type caught: ' + e.getTypeName());
System.debug('Message: ' + e.getMessage());
System.debug('Cause: ' + e.getCause()); // returns null
System.debug('Line number: ' + e.getLineNumber());
System.debug('Stack trace: ' + e.getStackTraceString());
}
Please refer this link to view other Exception Methods which will help for tracing your error
Let me know if you need more help. Thanks :)
Related
I need to send an email notification to the record owner and manager once the opportunity is closed-won.
adding only owner email works fine
adding only manager email works fine
But if I add both together with coma, {!$Record.Owner.Email},{!$Record.Engagement_Manager__r.Email} I'm getting error.
what is the correct way to add it?
You can try creating a Formula Resource in your flow like this but, in your case, using $Record.Owner.Email and $Record.Engagement_Manager__r.Email:
Then, you can use this Resource in your Email Action:
Try the below code and let me know if it works.
global class SendPurchaseOrderEmail {
WebService static void sendEmail(String poId) {
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
String theTemplate = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Purchase_Order_With_Items'].Id;
User theUser = [SELECT Id FROM User WHERE Name = 'user name goes here'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSaveAsActivity(false);
mail.setTemplateId(theTemplate);
mail.setWhatId(poId);
mail.setTargetObjectId(theUser.Id);
mail.setToAddresses(new String[] { 'TestUser#salesforce.com' ,'abc#test.com'}); //add other emails here.
emails.add(mail);
Messaging.sendEmail(emails);
}
}
Please refer below link for more details.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_sendemail.htm
This is because you have to pass a direct email address there.
Instead of that, you can create a collection variable, store the emails into it, then pass that variable to email addresses (collection) field.
Note: you can only store upto 5 emails into that colllection variable at a time.
Hi For that you can simply add collection Variable.
For that variable assign multiple values to it. So that you can send email to both record owner as well as manager.
From New Resource Select the Variable and click Allow Multiple Values and Data-type as text.
Then by using Assignment. Add the following email Address to it Please refer the below image.
I hope you have got the solution
Thanks
I am trying to handle the exceptions/errors generated by Python Snowflake connector.
connection = snowflake.connector.connect(
user='user',
password=''password,
account='account',
role='ACCOUNTADMIN'
)
If the connection is successful then it will return a snowflake object or else I would want to handle all the possible exception and print a custom message.
What are the possible exception snowflake.connector.connect method would generate.
How to handle all of those exceptions. (link to the documentation or an example would be really helpful)
If you have a look at the snowflake.connector.errors file you can see a list of all errors that can be returned by the snowflake connector. It doesn't say anywhere about the specific errors that can be returned by snowflake.connector.connect. Here is a list of the error types that I suspect can get returned:
class InterfaceError(Error)
class DatabaseError(Error)
class InternalError(DatabaseError)
class OperationalError(DatabaseError)
class InternalServerError(Error)
class ServiceUnavailableError(Error)
class GatewayTimeoutError(Error)
class ForbiddenError(Error)
class RequestTimeoutError(Error)
class BadRequest(Error)
class BadGatewayError(Error)
class MethodNotAllowed(Error)
class OtherHTTPRetryableError(Error)
class MissingDependencyError(Error)
Rather than trying to handle every error, you should only handle the errors that you know what to do with. For example, you wouldn't handle an InternalServerError unless you knew what to do to fix it. Instead, log it and let it fail.
Here is an example of how you would catch a bad username/password. You could then ask the user to re-enter their details:
import os
import snowflake.connector
from snowflake.connector.errors import DatabaseError, ProgrammingError
snowflake_account = os.environ['SNOWFLAKE_ACCOUNT']
if __name__ == '__main__':
try:
con = snowflake.connector.connect(
user='bad username', # <-------- Bad user
password='bad password', # <-------- Bad pass
account=snowflake_account # <-------- This is correct
)
except DatabaseError as db_ex:
if db_ex.errno == 250001:
print(f"Invalid username/password, please re-enter username and password...")
# code for user to re-enter username & pass
else:
raise
except Exception as ex:
# Log this
print(f"Some error you don't know how to handle {ex}")
raise
else:
try:
results = con.cursor().execute("select * from db.schema.table").fetchall()
print(results)
except ProgrammingError as db_ex:
print(f"Programming error: {db_ex}")
raise
finally:
con.close()
I've also put in an example of catching a ProgrammingError which can be raised when you enter some invalid SQL.
You can use try.. catch method in python
try:
self.mainsfconnection = sf.connect(
user=config.user,
password=config.password,
account=config.account,
warehouse=config.warehouse,
role=config.role,
database=config.database,
schema=config.schema)
# -- Snowflake : Default Session parameters
self.mainsfconnection.cursor().execute("USE ROLE {0}".format(config.role))
self.mainsfconnection.cursor().execute("USE WAREHOUSE {0}".format(config.warehouse))
self.mainsfconnection.cursor().execute("USE SCHEMA {0}.{1}".format(config.database, config.schema))
# -- Exception clause : snowflake
except sf.errors.ProgrammingError as e:
print('SQL Execu tion Error: {0}'.format(e.msg))
print('Snowflake Query Id: {0}'.format(e.sfqid))
print('Error Number: {0}'.format(e.errno))
print('SQL State: {0}'.format(e.sqlstate))
Here's a really good example from the docs, note there is no reason not to move the cur = and the connection = to below the try command (with proper indentation of course):
https://docs.snowflake.com/en/user-guide/python-connector-example.html#handling-errors
# Catching the syntax error
cur = con.cursor()
try:
cur.execute("SELECT * FROM testtable")
except snowflake.connector.errors.ProgrammingError as e:
# default error message
print(e)
# customer error message
print('Error {0} ({1}): {2} ({3})'.format(e.errno, e.sqlstate, e.msg, e.sfqid))
finally:
cur.close()
While implementing chat in react web app using XMPP, the issue I've faced is storing sent data in Mysql DB end from Mnesia.
I used the strophe library for this to implement chat part in the web environment.
I am totally new to this chat server.
Here the workflow I'm following
1. Connection and authenticating to a ejabber server.
2. Creating a muc_room with some users.
3. I'm trying to send a message to the already created group, Here I designed the serve like it will store the messages to archive table in MySQL from Mnesia DB.
4. Finally, I want to get all the rosters list.
But I am facing a struggle in 3rd point I can't see the sent message from my end to the created group in archive table and I think it stored temporarily in Mnesia DB.
Please refer the pasted code regarding sendmessage,
var messagetype = (type) ? type : 'chat';
var reply;
if (messagetype === 'groupchat') {
reply = window.$msg({
to: messgeTo,
from: connection.jid,
type: messagetype,
id: connection.getUniqueId()
}).c("body", {xmlns: window.Strophe.NS.CLIENT}).t(message);
}
else {
reply = window.$msg({to: messgeTo,
from: connection.jid,
type: messagetype
}).c("body", {xmlns: window.Strophe.NS.CLIENT}).t(message);
}
connection.send(reply.tree());
console.log('I sent ' + messgeTo + ': ' + message, reply.tree());
Please, try to give any ideas to fix this issue.
/* Edited code */
connection.muc.join(messageTo, messageTo.split('#')[0], function(st) {
console.log(st, 'status');
});
if (messagetype === 'groupchat') {
reply = window.$msg({
to: messageTo,
from: connection.jid,
type: messagetype,
id: connection.getUniqueId()
}).c("body").t(message).up()
.c('request', {'xmlns': window.Strophe.NS.RECEIPTS});
} else {
reply = window.$msg({to: messa`enter code here`geTo,
from: connection.jid,
type: messagetype
}).c("body").t(message).up()
}
connection.send(reply.tree());
console.log('I sent ' + messageTo + ': ' + message, reply.tree());
Before sending message to a chat group I've joined the muc room. After that prepared the message content and sent it.
I want to show a Feed back message in sales force Standard page on custom button click using visual force page on the basis of Apex class logic.Any one who can help me?For example if some thing successfully done then success message and if not error message should display on standard page.
You can create a new method to handle your messages
private void displayFeedback(ApexPages.Severity msgType, String message)
{
ApexPages.Message msg = new ApexPages.Message(msgType, message);
ApexPages.addMessage(msg);
}
Build your message you want to show..
displayFeedback(ApexPages.Severity.Error, String.valueOf(TripProfileHandlerServices.ERROR_SAVING_DATA + missingDataError));
Put this message in your VF page
<apex:pageMessages id="feedback" />
You will also have to rerender='feedback" when you want show the message after an event
If you put a <apex:messages /> in the page, you can use the message class to fill it up.
Could anyone please help me with authenticating to Google Plus using OAuth2? I am able to get the authentication window to display, login and confirm my application with my account, but for some reason the action event is never fired. I get a screen saying Please copy this code, switch to your application and paste it there.
How do i get the action event to fire?
Thanks in advance.
Edit:
My code is as follows:
Hi Shai, thanks for the response, my code for the authentication is as follows:
Oauth2 auth2 = new Oauth2("https://accounts.google.com/o/oauth2/auth", "Client_Id", "urn:ietf:wg:oauth:2.0:oob or http://localhost", "openid", "https://accounts.google.com/o/oauth2/token", "Client_Secret");
Oauth2.setBackToParent(true);
auth2.showAuthentication(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof String) {
String token = (String) evt.getSource();
String expires = Oauth2.getExpires();
GOOGLE_TOKEN = token;
System.out.println("recived a token " + token + " which expires on " + expires);
//store token for future queries.
} else {
Exception err = (Exception) evt.getSource();
err.printStackTrace();
Dialog.show("Error", "An error occurred while logging in: " + err, "OK", null);
}
}
});
The "auth2.showAuthentication" works well, and allows you to pass through for the user to authorize the application but then once the user authorizes the application the "actionlistener" is never called, I never hit the callback. How can i force the callback to fire to return the token?
I have been struggling with the same issue. I finally found out that the problem lies in the setup of the WebBrowser inside Oauth2.createLoginComponent(): the onStart() handler waits for a URL starting with your supplied redirect URI, but this URL never appears. The final Google page, the one that brings the token, has a URL starting with "https://accounts.google.com/o/oauth2/approval?", not with the redirect URI.
According to Google's documentation the token will be supplied inside the page title, but this appears not to be the case with the native browser in CodeName One. I therefore ended up scraping the HTML document for an input with id="code", whose value is the token we're looking for. The scraping has to take place after the page has been loaded, i.e. in the onLoad() event, not in onStart().
Hope this helps, it worked for me.