Workflow Rule to send email alert - salesforce

I need a work flow rule which should satisfy below conditions
email should be sent to lead owner when a Specific__user(specific user i have here) creates a lead
and email should be sent when Specific__user changes lead owner
To send email i have email alert designed already.
Using below but it is not working
Rule criteria: created, and every time it's edited
AND(ISCHANGED( OwnerId ), PRIORVALUE( OwnerId) = 'Specific__user_Id')

If you want the same email to be sent for the following conditions, try using the formula below.
Send email when a specific user creates a Lead.
Send email when a specific user changes a the Lead Owner of an existing Lead.
OR(
AND(
ISNEW(),
CreatedBy.Id = Specific__user_Id
AND(
ISCHANGED(OwnerId),
$User.Id = Specific__user_Id
)
)

Related

Salesforce Apex not updating record

I am trying to do a simple update in sandbox on a field that is in the Account Object in Salesforce but it does not seem like it is committing. I follow the basics of pulling and updating a record as stated below:
String accountId = '12345'
Account queriedAccount = [SELECT Id, Communication_Bubble__c FROM Account WHERE id = :accountId limit 1];
System.debug(queriedAccount);
// set the field i want to update
queriedAccount.Communication_Bubble__c = 'New Donor';
// update field
update queriedAccount;
// run select again to see if update went through
Account queriedAccount2 = [SELECT Id, Communication_Bubble__c FROM Account WHERE id = :accountId limit 1];
System.debug(queriedAccount2);
Looking at the logs after this piece of code is ran shows that the update went through as I was able to pull the account and it displays the Account with the updated field. Here are what both of the debugs display:
Debug1: |Debug|Account:{Id=12345} (communication bubble is null)
Debug2: |Debug|Account:{Id=12345,Communication_Bubble=New Donor}
From the above it seems like the update is working exactly how it should be. But when I go to the account in the dashboard, or pull the account with a query in the developer console that Communication Bubble field is still blank.
It seems like I am missing some sort of commit but I cant figure out what it is.
No way this compiles, did you anonymise it too much?
Communication_Bubble - actual field name is probably Communication_Bubble__c.
You query and set a field value on queriedAccount but what you actually save is another variable queriedContact?
There's low chance you actually have some code that resets the value (would have to be #future, time-based workflow etc to work but not be detected in 2nd query... But my vote goes to "you just updated wrong record"

google app engine: concurrent user registrations

I know this is a classical problem, but I still don't know how to do it. On Google App Engine, I have a member registration form which uses jQuery's validation to check if a username exists.
There of course is a concurrency problem: several users try to register, enter the same username, Validation finds the username available, and allow them to press "Add" at the approximately same time. Validation wouldn't detect this. In my application, username, email, and Personal ID should all be unique. How do I prevent the following code from having the concurrency problem:
member = Member()
member.username = self.request.get('username')
member.Pid = self.request.get('Pid')
member.email = self.request.get('email')
...
As the uniqueness constraint is on username, you have to use it as key in datastore and use transactions.
def txn():
key = ndb.Key(Member, username)
member = key.get()
if member is not None:
raise CustomAlreadyExistsException(member) # This will abort txn
member = Member(
id=username,
Pid=self.request.get('Pid'),
email=self.request.get('email'),
...)
member.put()
ndb.transaction(txn)
This makes sure only one person can register a username.
The jQuery helper would check if ndb.Key(Member, userid).get() gives a result or not. The GET is not transactional.
To improve usability client side in "reserving" a username after checking availability, you could use memcached as suggested by Daniel, but I'd call YAGNI, skip the complexity and rather let some people get validation error after submitting the form. Note that memcached is best effort and has no guarantees about anything.
If you need guaranteed uniqueness on multiple fields, you have to add Model classes for them and check in a cross group (XG) transaction.
class Pid(ndb.Model):
member = ndb.KeyProperty()
class Email(ndb.Model):
member = ndb.KeyProperty()
class Member(ndb.Model):
pid = ndb.KeyProperty()
email = ndb.KeyProperty()
#property
def pid_value(self):
return self.pid.id()
#property
def email_value(self):
return self.email.id()
def txn():
member_key = ndb.Key(Member, username)
pid_key = ndb.Key(PersonalId, self.request.get('Pid'))
email_key = ndb.Key(Email, self.request.get('email'))
member, pid, email = ndb.get_multi([member_key, pid_key, email_key])
if member is not None or pid is not None or email is not None:
raise CustomAlreadyExistsException(member, pid, email) # This will abort txn
# Create instances referencing each other
email = Email(key=email_key, member=member_key)
pid = Pid(key=pid_key, member=member_key)
member = Member(
key=member_key,
pid=pid_key,
email=email_key,
...)
ndb.put_multi([member, pid, email])
ndb.transaction(txn, xg=True)
This is a great use for memcache. Your Ajax validation function should put an entry into memcache to record that the username has been requested. It should also check both memcache and the datastore to ensure that the username is free. Similarly, the registration code should check memcache to ensure that the current user is the one who requested the username.
This nicely solves your concurrency problem, and the best thing is that entries in memcache expire by themselves, either on a timed basis or when the cache gets too full.
I agreed with tesdal.
If you still want to implement the memcache tric sugested by Daniel, you should do something like "memcache.add(usernameA, dummy value, short period);". So you know that usernameA is reserved for a short period and wont conflict with "memcache.add(usernameB, ..."

Accessing Open Activities fields linked to a Case in salesforce

Using email to case I am able to save email body in the Open activities related section of the case.
I want to write a query / way in case trigger to fetch the email body attached to a activity into a string so that I can parse it to get certain values.
I am using Querying sObject Relationships but not able to get anywhere...
Can someone help me with this?
If you're using email-to-case the email's body should be embedded into Case already?
Try one of these 2 queries (of course provide an id that will work for you)
select Id, FromAddress, HtmlBody, Incoming, Subject, TextBody, ToAddress
FROM EmailMessage
WHERE ParentId = '500D000000KUXYP'
SELECT Id, Subject, (SELECT TextBody FROM EmailMessages)
FROM Case
WHERE Id = '500D000000KUXYP'
Sorry for replying so late.
As the core of my question was to parse the incoming email on the salesforce. I discontinued the email to case approach and used the Inbound Email handler provided buy the Salesforce and written my own APEX class by extending the handler.
In the same class, I accessed the case object and updated the fields required.

Is it possible to check if a User is Locked Out?

Using the Salesforce Web Services API is it possible to check (or query) if a User is Locked Out (if they have attempted to log in unsuccessfully too many times and are therefore blocked from logging in)?
Although there is no specific field on the User object to indicate that they are locked out, you can query the LoginHistory object.
select Id, UserId, LoginTime, Status from LoginHistory where
UserId = 'xxxxxxxxx' order by LoginTime desc limit 20
Then loop through the results, checking the value of the Status field. If the user has been locked out, the most recent login attempts will have a value of "Password Lockout" in this field.
Other possible values of this Status field include:
Success
User is Inactive
Invalid Password
Failed: API security token required
Failed: Computer activation pending
Failed: Computer activation required
Failed: Invalid Timestamp
Failed: Mobile License Required
Nevermind; I found the answer.
It says in the documentation:
The password lockout status and the ability to reset the User locked-out status is not available via the API. You must check and reset the User password lockout status using the user interface.
For admin users - it's now possible to unlock users on iphone / ipad via the SalesforceA mobile app. https://itunes.apple.com/au/app/salesforcea/id731117958?mt=8
In Apex, I can check the IsPasswordLocked field on UserLogin object to check if a User is locked out or not by using the following SOQL -:
[SELECT IsPasswordLocked FROM UserLogin
WHERE UserId = 'ENTER YOUR USER ID HERE'];

Insert an ID into $this->request->data array before saving in CakePHP

I have a contact form which asks users for their name, email address and message.
The name and email address are stored in Person and the message is stored in Message
Message belongs to Person so when I do:
$this->Person->Message->saveAll($this->request->data)
..the name and email address are INSERTED in the people table and the message is INSERTED in the messages table with a person_id.
So far, so good.
Now, what I want to do is provide a way for Person to be UPDATED and Message to be INSERTED if the user (identified by their email address) comes back and submits a second message.
The only way I have found to do this is to run find on Person to see if there's a record containing the email address submitted in the form. If there is, I use array_merge to add it to $this->request->data['Person']. This works, but this feels like a bit of a hackish way of doing things.
Is there a more straightforward way of doing this?
If you use the beforeSave() method of the Person Model.
# App/Model/Person.php
function beforeSave()
{
if(empty($this->data['Person']['id'])
{
$person = $this->findByEmail($this->data['Person']['email']);
if(!empty($person))
{
$this->data['Person']['id'] = $person['Person']['id'];
}
}
return true;
}
After finding your Person, you could just set person_id of your Message und just run save on it, so you don't have to save the person again.

Resources