Skip to content

Instantly share code, notes, and snippets.

View mailtoharshit's full-sized avatar
🤔
Always Curious

Harshit Pandey mailtoharshit

🤔
Always Curious
View GitHub Profile
@mailtoharshit
mailtoharshit / gist:3493988
Created August 28, 2012 00:58
SOQL PolyMorphism
SELECT
TYPEOF What
WHEN Account THEN Phone, NumberOfEmployees
WHEN Opportunity THEN Amount, CloseDate
WHEN Campaign THEN ExpectedRevenue, StartDate
ELSE Name
END
FROM Event
The equals method with this signature:
public Boolean equals(Object obj) {
// Your implementation
}
Keep in mind the following when implementing the equals method. Assuming x, y, and z are non-null instances of your
class, the equals method must be:
◊ Reflexive: x.equals(x)
◊ Symmetric: x.equals(y) should return true if and only if y.equals(x) returns true
◊ Transitive: if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true
public class PairNumbers {
Integer x,y;
public PairNumbers(Integer a, Integer b) {
x=a;
y=b;
}
public Boolean equals(Object obj) {
if (obj instanceof PairNumbers) {
PairNumbers p = (PairNumbers)obj;
return ((x==p.x) && (y==p.y));
Map<PairNumbers, String> m = new Map<PairNumbers, String>();
PairNumbers p1 = new PairNumbers(1,2);
PairNumbers p2 = new PairNumbers(3,4);
// Duplicate key
PairNumbers p3 = new PairNumbers(1,2);
m.put(p1, 'first');
153
Developer Console Enhancements Apex Code Enhancements
m.put(p2, 'second');
m.put(p3, 'third');
public class MyDynamicSolution {
@future
public static void updateOwner(List<ID> objIds, ID newOwnerId) {
// Validate input
System.assert(objIds != null);
System.assert(objIds.size() > 0);
System.assert(newOwnerId != null);
// Get the sObject token from the first ID
// (the List contains IDs of sObjects of the same type).
Schema.SObjectType token = objIds[0].getSObjectType();
@mailtoharshit
mailtoharshit / ControlledTriggerHelper.java
Created November 1, 2012 23:41
ControlledTriggerHelper
//TODO: This class will stop allowing trigger to fire-in twice
public class ControlledTriggerHelper {
// initialize a variable to hold state
private static boolean alreadyModified = false;
// get the state
public static boolean isAlreadyModified() {
return alreadyModified;
@mailtoharshit
mailtoharshit / gist:3997658
Created November 1, 2012 23:50
TestTrigger.trigger
if ( Trigger.isAfter )
{
System.debug('in after trigger; alreadyModified: ' + ControlledTriggerHelper.isAlreadyModified());
if (!ControlledTriggerHelper.isAlreadyModified() )
{
ControlledTriggerHelper.setAlreadyModified();
// do something...
}
}
@mailtoharshit
mailtoharshit / gist:3997673
Created November 1, 2012 23:52
example.Trigger
if (!RecursiveTriggerHelper.isAlreadyModified() )
{
RecursiveTriggerHelper.setAlreadyModified();
myclass.CheckOwnerChange(oldOpportunity,NewOpportunity);
}
}
trigger OpportunityTrigger on Opportunity (before Update, after Update)
{
//Poor Design
for (Account acc : Trigger.New)
{
//Creating instance of class for each trigger call
OpportunityRecordType art = new OpportunityRecordType()
......
}
trigger OpportunityTrigger on Opportunity(before Update, after Update) {
for (Account acc: Trigger.New) {
//Creating instance of class for each trigger call
OpportunityRecordType art = OpportunityRecordType.getInstance();
......
}
}