public class Utilities { public static Boolean isOppyTrgExecuting = false; } if(Utilities.isOliTrgExecuting == false) { Utilities.isOliTrgExecuting = true; // Do stuff }
Friday, May 22, 2015
Check for recursive triggers.
Get fields of object.
public static String GetObjectFields(String strSObjectName) { // Get the field names SObjectType sot = Schema.getGlobalDescribe().get(strSObjectName); if (sot == null) return null; String theFields = ''; List lstFields = sot.getDescribe().fields.getMap().values(); for(Schema.SObjectField s : lstFields) { String theName = s.getDescribe().LocalName; theFields += theName + ','; } // Trim last comma theFields = theFields.subString(0, theFields.length() - 1); return theFields; }
Test for person account.
We basically just need to grab the correct account type record id and assign it to the account and you of course need person accounts enabled on your org.
String RecordTypeId = [SELECT Id FROM RecordType WHERE (Name = 'Person Account') AND (sObjectType = 'Account')].Id;
Account a = new Account(
RecordTypeID = RecordTypeId,
LastName = System.now().millisecond() + 'Testing Lastname'
);
insert a;
Test for products without @isAllTestData
@isTest private class TrgOpportunityTest { @isTest static void test_method_one() { Account a = new Account(); a.Name = 'Wallyu'; insert a; Opportunity o = new Opportunity( Name = 'Merchandisebo', Autorenew__c = 'Yes', Account = a, StageName = 'Contract', CloseDate = DateTime.Now().Date(), Term_2_License_Start_Date__c = DateTime.Now().Date(), Term_2_License_End_Date__c = DateTime.Now().Date().addYears(1), HasBeenRenewed__c = false, Bill_When__c = 'In Arrears'); insert o; System.debug(LoggingLevel.WARN, '@@@TrgOpportunityTest.o : ' + o); Product2 p2 = new Product2(Name='Test Productrrrr',isActive=true); insert p2; Id pricebookId = Test.getStandardPricebookId(); PricebookEntry pbe = new PricebookEntry(Pricebook2Id=pricebookId, Product2Id=p2.Id, UnitPrice=99, isActive=true); insert pbe; OpportunityLineItem oli = new OpportunityLineItem(PriceBookEntryId=pbe.Id, OpportunityId=o.Id, Quantity=1, TotalPrice=99,Description='sdfsdfsdf'); List olilist=new List{oli}; insert (olilist); Test.startTest(); o.StageName = 'Purchased'; upsert o; System.debug(LoggingLevel.WARN, '@@@TrgOpportunityTest.o AFTER UPSERT : ' + o); Test.stopTest(); } }
Simple wrapper class example.
public class Checkbox_Class { List accountList = new List(); List selectedAccounts = new List(); public List getAccounts() { for(Account a : [select Id, Name, AccountNumber, Phone from Account limit 5]) accountList.add(new accountwrapper(a)); return accountList; } public class accountwrapper { public Account acc{get; set;} public Boolean selected {get; set;} public accountwrapper(Account a) { acc = a; selected = false; } } }
Missing Reset My Security Token
Instead of messing around trying to figure out the IP ranges and security settings you can use this URL hack:
{your domain}/_ui/system/security/ResetApiTokenEdit?retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DPersonalInfo&setupid=ResetApiToken
Subscribe to:
Posts (Atom)