Transaction security policy for multiple logins

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I need to modify the existing transaction security policy to trigger if user logs in from multiple IP addresses in past 8 hours. I'm using the below SFDC example policy. Can someone give a hand on how to tweak the below code to trigger for 8 hours. Currently the policy is configured to trigger for past 24 hours.



global class LoginPolicyCondition implements TxnSecurity.PolicyCondition 
public boolean evaluate(TxnSecurity.Event e)
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime = LAST_N_DAYS:1
GROUP BY SourceIp];
if(!results.isEmpty() && results.size() > 1)
return true;

return false;











share|improve this question





















  • This is mostly identical to this question but with more context. Please edit your questions to expand on them rather than creating duplication.
    – David Reed
    4 hours ago










  • David - I deleted the identical question since it was duplicate as you pointed. Thanks
    – VBALearner
    4 hours ago
















up vote
2
down vote

favorite












I need to modify the existing transaction security policy to trigger if user logs in from multiple IP addresses in past 8 hours. I'm using the below SFDC example policy. Can someone give a hand on how to tweak the below code to trigger for 8 hours. Currently the policy is configured to trigger for past 24 hours.



global class LoginPolicyCondition implements TxnSecurity.PolicyCondition 
public boolean evaluate(TxnSecurity.Event e)
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime = LAST_N_DAYS:1
GROUP BY SourceIp];
if(!results.isEmpty() && results.size() > 1)
return true;

return false;











share|improve this question





















  • This is mostly identical to this question but with more context. Please edit your questions to expand on them rather than creating duplication.
    – David Reed
    4 hours ago










  • David - I deleted the identical question since it was duplicate as you pointed. Thanks
    – VBALearner
    4 hours ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I need to modify the existing transaction security policy to trigger if user logs in from multiple IP addresses in past 8 hours. I'm using the below SFDC example policy. Can someone give a hand on how to tweak the below code to trigger for 8 hours. Currently the policy is configured to trigger for past 24 hours.



global class LoginPolicyCondition implements TxnSecurity.PolicyCondition 
public boolean evaluate(TxnSecurity.Event e)
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime = LAST_N_DAYS:1
GROUP BY SourceIp];
if(!results.isEmpty() && results.size() > 1)
return true;

return false;











share|improve this question













I need to modify the existing transaction security policy to trigger if user logs in from multiple IP addresses in past 8 hours. I'm using the below SFDC example policy. Can someone give a hand on how to tweak the below code to trigger for 8 hours. Currently the policy is configured to trigger for past 24 hours.



global class LoginPolicyCondition implements TxnSecurity.PolicyCondition 
public boolean evaluate(TxnSecurity.Event e)
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime = LAST_N_DAYS:1
GROUP BY SourceIp];
if(!results.isEmpty() && results.size() > 1)
return true;

return false;








transaction shield






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 5 hours ago









VBALearner

112




112











  • This is mostly identical to this question but with more context. Please edit your questions to expand on them rather than creating duplication.
    – David Reed
    4 hours ago










  • David - I deleted the identical question since it was duplicate as you pointed. Thanks
    – VBALearner
    4 hours ago
















  • This is mostly identical to this question but with more context. Please edit your questions to expand on them rather than creating duplication.
    – David Reed
    4 hours ago










  • David - I deleted the identical question since it was duplicate as you pointed. Thanks
    – VBALearner
    4 hours ago















This is mostly identical to this question but with more context. Please edit your questions to expand on them rather than creating duplication.
– David Reed
4 hours ago




This is mostly identical to this question but with more context. Please edit your questions to expand on them rather than creating duplication.
– David Reed
4 hours ago












David - I deleted the identical question since it was duplicate as you pointed. Thanks
– VBALearner
4 hours ago




David - I deleted the identical question since it was duplicate as you pointed. Thanks
– VBALearner
4 hours ago










1 Answer
1






active

oldest

votes

















up vote
2
down vote













There is no SOQL Date Literal equivalent to to LAST_N_DAYS:1 that will give you a period of 8 hours.



Instead, you can just calculate the date range and use that in the SOQL query instead.



DateTime eightHoursAgo = DateTime.now().addHours(-8);
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime >= :eightHoursAgo
GROUP BY SourceIp];
return (!results.isEmpty() && results.size() > 1);





share|improve this answer




















  • That makes perfect sense. Appreciate your help on this.
    – VBALearner
    4 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f238557%2ftransaction-security-policy-for-multiple-logins%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













There is no SOQL Date Literal equivalent to to LAST_N_DAYS:1 that will give you a period of 8 hours.



Instead, you can just calculate the date range and use that in the SOQL query instead.



DateTime eightHoursAgo = DateTime.now().addHours(-8);
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime >= :eightHoursAgo
GROUP BY SourceIp];
return (!results.isEmpty() && results.size() > 1);





share|improve this answer




















  • That makes perfect sense. Appreciate your help on this.
    – VBALearner
    4 hours ago















up vote
2
down vote













There is no SOQL Date Literal equivalent to to LAST_N_DAYS:1 that will give you a period of 8 hours.



Instead, you can just calculate the date range and use that in the SOQL query instead.



DateTime eightHoursAgo = DateTime.now().addHours(-8);
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime >= :eightHoursAgo
GROUP BY SourceIp];
return (!results.isEmpty() && results.size() > 1);





share|improve this answer




















  • That makes perfect sense. Appreciate your help on this.
    – VBALearner
    4 hours ago













up vote
2
down vote










up vote
2
down vote









There is no SOQL Date Literal equivalent to to LAST_N_DAYS:1 that will give you a period of 8 hours.



Instead, you can just calculate the date range and use that in the SOQL query instead.



DateTime eightHoursAgo = DateTime.now().addHours(-8);
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime >= :eightHoursAgo
GROUP BY SourceIp];
return (!results.isEmpty() && results.size() > 1);





share|improve this answer












There is no SOQL Date Literal equivalent to to LAST_N_DAYS:1 that will give you a period of 8 hours.



Instead, you can just calculate the date range and use that in the SOQL query instead.



DateTime eightHoursAgo = DateTime.now().addHours(-8);
AggregateResult results = [SELECT SourceIp
FROM LoginHistory
WHERE UserId = :e.userId
AND LoginTime >= :eightHoursAgo
GROUP BY SourceIp];
return (!results.isEmpty() && results.size() > 1);






share|improve this answer












share|improve this answer



share|improve this answer










answered 5 hours ago









Daniel Ballinger

70.8k15145377




70.8k15145377











  • That makes perfect sense. Appreciate your help on this.
    – VBALearner
    4 hours ago

















  • That makes perfect sense. Appreciate your help on this.
    – VBALearner
    4 hours ago
















That makes perfect sense. Appreciate your help on this.
– VBALearner
4 hours ago





That makes perfect sense. Appreciate your help on this.
– VBALearner
4 hours ago


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f238557%2ftransaction-security-policy-for-multiple-logins%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery