Here’s how mailbags work:
I’m creating a mailbag because:
TL:DR mailbags are like this, minus the dating. I swear I only visited that site for research purposes =)
Mailbag Archives
Date | Topic |
2019.04.23 | How can I be productive? |
2017.04.30 | What’s the story behind the “SFDC99” name? |
2017.04.29 | Where is Apex Academy #4? |
2016.06.30 | Are certifications enough to get a job? (#2) |
2016.04.28 | How’d you get into Google? |
2016.02.15 | Lack of confidence |
2015.07.13 | Am I writing good code? |
2015.03.07 | Is getting certified enough? (#1) |
2015.03.07 | Salesforce vs. its competitors |
2015.03.07 | What to learn first? |
2015.02.16 | Going from developer to architect |
2015.02.12 | Consult or work in-house? |
2015.02.10 | How to study Head First Java |
2015.02.10 | Which Apex book? |
2015.02.10 | Older person – should I still learn Salesforce? |
2015.02.06 | Remote job opportunities |
2015.02.06 | Learning to code vs. actual coding |
2015.02.02 | Learning code vs. getting certified |
2015.02.02 | How do I learn Visualforce? |
2015.01.28 | Convincing the boss to let me work remotely |
2015.01.27 | No master-detail relationships with Leads |
2015.01.27 | Passing the first Interview |
Hello David,
You are awesome, your website is so inspiring and informative. You are inspiration and my role model in journey to become a Successful Salesforce Technical Architect.Hope, we’ll meet soon.
Question:
I wanted to know that is there any website or something (Excluding Trailhead) where I can find lots for trigger, apex class related problems. Where we can test our skill ?
for example, websites like codechef, hackerrank and other coding platform provide the problems to solve.
Thank you,
Anish
Thank you Anish!!
I don’t know of any of these platforms, though you can definitely try my final project in bit.ly/go-apex ! It’s similar to the project they used to give in the Platform Developer II (aka Advanced Developer) certification.
Thank you so much David. I am heading towards my first certification i.e. Salesforce App Builder and I just wanted to know that if I am a Application Architect then do I have to maintain all 4 certification that are (App builder, PD1, Sharing and Visibility Designer and Data Architecture and Management Designer) and as Technical Architect how many certifiction currently you are maintaining?
I maintain a ton lol. Every March is a rough month for me, but, it’s well worth it!
Hi David,
I’m trying to display videos as a part of a Visual Flow in salesforce Lightning. I’m sure there is no functionality present to embed videos in visual flows. Please suggest me a way to achieve the same.
Not sure about this sorry!
Mavensmate does not seem to be available for download anymore. Is there another IDE that I could use to follow along with your tutorials?
Dev console for now!
Hi David, I want to do PD1 and PD2 ceritification, what will be needed..
Hi David, I want to do PD1 and PD2 ceritification, what will be needed.
I have a few questions.
1. I am trying to develop a account search page. The results must include the following columns account name, billing state/province, phone and website. The code I have so far but it is not coming back with the accounts.
2. Develop a grid of accouunt which can be selected. Once selected and the “Show Selected Accounts” button is clicked, information from the selected accounts is displayed in the “Selected Accounts” table. How do I do this and were do I start. The code I have is is bringing up contacts not accounts.
3. Produce a page which displays Accounts and related contact using only one query.
1. CODE
Search Text
2. CODE
3. CODE APEX
public class accountcontact1
{
list wraplist=new list();
public accountcontact1()
{
Map accMap=new Map();
for(account a:[SELECT createdby.name,CreatedbyID,Account.Name,(SELECT
name,Contact.FirstName, Contact.LastName
FROM Account.Contacts) FROM Account])
{
AccountWrapper accWrap=accMap.get(a.CreatedBy.name);
// AccountWrapper accWrap=accMap.get(a.CreatedBy.name);
if (null==accWrap)
{
accWrap=new AccountWrapper();
accMap.put(a.CreatedByname, accWrap);
accWrap.userid=a.CreatedByid;
// accMap.put(a.CreatedBy.name, accWrap);
accWrap.username=a.CreatedBy.name;
}
accWrap.accounts.add(a);
}
wrapList=accMap.values();
}
public list getaccounts()
{
return wraplist;
}
public class AccountWrapper
{
public id userid {get; set;}
public string username {get; set;}
public List accounts {get; set;}
public AccountWrapper()
{
accounts=new List();
}
}
}
3. VF CODE
2. CODE
1. CODE
Search Text
When I tried out this example from Apex Academy, I’m getting as error :”Initial term of a field expression must be a field sObject :list. What am I doing wrong?
trigger LeadingCompetitor on Opportunity (before insert) {
for ( Opportunity opp :Trigger.New){
// list of the competitor prices on the opportunity
List competitorPrices = new List();
competitorPrices.add(opp.Competitor_1_Price__c);
competitorPrices.add(opp.Competitor_2_Price__c);
competitorPrices.add(opp.Competitor_3_Price__c);
// list of the competitors on the opportunity
List competitors = new List();
competitors.add(opp.Competitor_1__c);
competitors.add(opp.Competitor_1__c);
competitors.add(opp.Competitor_1__c);
//system.debug(competitorPrices.get[0]);
Decimal LowestPrice ;
Integer lowestpriceposition=0;
for (Integer i=0;i< competitorPrices.size();i++)
{
Decimal currentprice = competitorPrices.get[i];
if ((LowestPrice==null)|| (competitorPrices.get[i]<LowestPrice))
{
LowestPrice= competitorPrices.get[i];
}
lowestpriceposition =i;
}
opp.Leading_Competitor__c = competitors.get[lowestpriceposition];
}
}
Hi David Liu,
i am facing issue while I am uploading and processing above 3000 records using vf page. it’s throw the error like, onclick java script button or link was encountered and limit.system exception:Regex too complicated.
i am providing code and screen shot below please resolve this issue
javascript code:
{!REQUIRESCRIPT(“/soap/ajax/30.0/connection.js”)}
{!REQUIRESCRIPT(“/soap/ajax/30.0/apex.js”)}
sforce.apex.execute(“EUFileHandler”,”CSVparse”,{recordID:'{!Subscription_Upload__c.Id}’});
alert(“Fan Record(s) processed. Please find successful Fan uploads under the Subscription Uploads tab, and duplicate fan uploads under the Sub Upload Failures tab.”);
File handler:
global class EUFileHandler { // 12 th line
private static Subscription_Upload__c originalSU;
webservice static void CSVparse(ID recordID){
List originalSUlist = [SELECT ID, Mailing_List__c FROM Subscription_Upload__c WHERE ID =:recordID];
for(Subscription_Upload__c su : originalSUlist){
su.File_Processed__c=true;
update su;
}
List at = [SELECT ID, Body, Name FROM Attachment WHERE ParentID =:recordID];
System.Debug(‘ check at ‘+at);
System.Debug(at[0].Body);
originalSU = originalSUlist[0];
//Fan__c src;
parseAttachments(at); // 30 th line
}
global static void parseAttachments(list att){
List cObjsToInsert = new List();
List sub = new List();
List subh = new List();
String src;
for(attachment a: att){
List<List> parsedCSV;
try{
System.Debug(‘ check base64 ‘+a.Body.ToString());
parsedCSV = EUUploadUtil.parseCSV(a.Body.ToString(), true);// 46th line
System.Debug(‘ check parsedCSV ‘+parsedCSV);
} catch(StringException e) {
System.Debug(‘StringException caught: Please encode the attached CSV file in UTF-8 format, and try again! ‘ + e.getMessage());
}
for(List line:parsedCSV){
System.Debug(‘ check line ‘+line);
Fan__c c = new Fan__c();
if (line.size()>6){
c.Name=line[5]+’ ‘+line[6];
c.First_Name__c=line[5];
c.Last_Name__c=line[6];
}
if(String.IsNotBlank(line[0])){
c.Email__c=line[0];
} else {
c.Email__c=’No email provided’;
}
if (line.size()>4){
if(String.IsNotBlank(line[4])){
c.Source__c=line[4];
} else {
c.Source__c=’No source provided’;
}
}
if(line.size()>7){
c.Mobile_Phone__c=line[7];
}
if(line.size()>8 && string.IsNotBlank(line[8])){
c.Birthdate__c=date.parse(line[8]);
}
if(line.size()>9){
c.Gender__c=line[9];
}
if(line.size()>10){
c.Address_1__c=line[10];
}
if(line.size()>11){
c.City__c=line[11];
}
if(line.size()>12){
c.State__c=line[12];
}
if(line.size()>13){
c.Country_Region__c=line[13];
}
if(line.size()>14){
c.Postal_Code__c=line[14];
}
if(line.size()>15){
c.Preferred_Language__c=line[15];
}
if(line.size()>16){
c.Facebook_Page__c=line[16];
}
if(line.size()>17){
c.Twitter_Handle__c=line[17];
}
if(line.size()>18){
c.MyspaceId__c=line[18];
}
c.Subscription_Upload_source__c=originalSU.ID;
src = c.Source__c;
cObjsToInsert.Add(c);
}
}
Set emails = new Set();
System.Debug(‘SET’ + emails);
Map fanMap = new Map();
List newF = new List();
List dupeList = new List();
for(Fan__c f : cObjsToInsert) {
emails.Add(f.Email__c);
System.Debug(‘check email ‘+f.Email__c);
}
List ef = [SELECT ID, Name, Email__c FROM Fan__c WHERE Email__c IN : emails];
for(Fan__c existingFan : ef) {
fanMap.put(existingFan.Email__c.toLowerCase(), existingFan);
System.Debug(‘check existing fan ‘+existingFan);
}
for(Fan__c f : cObjsToInsert) {
System.Debug(‘check email ‘+f.Email__c);
System.Debug(‘check Name ‘+f.Name);
if(!fanMap.containsKey(f.Email__c.toLowerCase()) && f.Email__c != ‘No email provided’) {
newF.Add(f);
} else {
SubUploadFailures__c d = new SubUploadFailures__c();
d.Name=f.Name;
d.Email__c=f.Email__c;
d.Mobile_Phone__c=f.Mobile_Phone__c;
d.Country_Region__c=f.Country_Region__c;
d.Source__c=f.Source__c;
d.Birthdate__c=f.Birthdate__c;
d.Gender__c=f.Gender__c;
d.Address1__c=f.Address_1__c;
d.Postal_Code__c=f.Postal_Code__c;
d.Preferred_Language__c=f.Preferred_Language__c;
d.Facebook_Page__c=f.Facebook_Page__c;
d.Twitter_Handle__c=f.Twitter_Handle__c;
d.Myspace_ID__c=f.MyspaceId__c;
dupeList.Add(d);
}
}
System.Debug(‘check newF ‘+newF);
System.Debug(‘check dupeList ‘+dupeList);
Database.insert(newF, false);
Database.insert(dupeList, false);
List nfa = [SELECT ID, Name, Email__c, Source__c FROM Fan__c WHERE ID IN : newF OR ID IN :ef];
for(Fan__c nf : nfa){
Subscription__c s = new Subscription__c();
s.Name= nf.Name;
s.Fan_ID__c=nf.ID;
s.Mailing_List_ID__c=originalSU.Mailing_List__c;
s.Source__c=src;
s.Active__c=true;
Subscription_History__c sh = new Subscription_History__c();
sh.Name=nf.Name;
sh.Fan_ID__c=nf.ID;
sh.Action__c=’Sign Up’;
sh.Mailing_List_ID__c=originalSU.Mailing_List__c;
sh.Source__c=src;
sub.Add(s);
subh.Add(sh);
}
System.Debug(‘ check cobjstoinsert ‘+cObjsToInsert);
System.Debug(‘check sub ‘+sub);
System.Debug(‘check subh ‘+subh);
Database.insert(sub, false);
Database.insert(subh, false);
}
}
Utill class :
public static list<list> parseCSV(String contents,Boolean skipHeaders) {
list<list> allFields = new List<List>();
// replace instances where a double quote begins a field containing a comma
// in this case you get a double quote followed by a doubled double quote
// do this for beginning and end of a field
contents = contents.replaceAll(‘,”””‘,’,”DBLQT’).replaceall(‘”””,’,’DBLQT”,’);//19 th line
// now replace all remaining double quotes – do this so that we can reconstruct
// fields with commas inside assuming they begin and end with a double quote
contents = contents.replaceAll(‘””‘,’DBLQT’);// 22 line
// we are not attempting to handle fields with a newline inside of them
// so, split on newline to get the spreadsheet rows
list lines=new list();
try {
lines = contents.split(‘\n’);
} catch (System.ListException e) {
System.debug(‘Limits exceeded? ‘+e.getMessage());
}
integer num=0;
for(string line :lines) {
// check for blank CSV lines (only commas)
if(line.replaceAll(‘,’,”).trim().length()==0)
break;
list fields=line.split(‘,’);
list cleanFields=new list();
string compositeField;
boolean makeCompositeField=false;
for(string field : fields) {
if(field.startsWith(‘”‘) && field.endsWith(‘”‘)) {
cleanFields.add(field.replaceAll(‘DBLQT’,'”‘).removeStart(‘”‘).removeEnd(‘”‘));
} else if(field.startsWith(‘”‘)) {
makeCompositeField = true;
compositeField = field;
} else if(field.endsWith(‘”‘)) {
compositeField += ‘,’ + field;
cleanFields.add(compositeField.replaceAll(‘DBLQT’,'”‘).removeStart(‘”‘).removeEnd(‘”‘));
makeCompositeField = false;
} else if(makeCompositeField) {
compositeField += ‘,’ + field;
} else{
cleanFields.add(field.replaceAll(‘DBLQT’,'”‘).removeStart(‘”‘).removeEnd(‘”‘));
}
}
allFields.add(cleanFields);
}
if(skipHeaders)
allFields.remove(0);
// allFields.remove(0);
return allFields;
}
public class EUUploadUtil {
public static list<list> parseCSV(String contents,Boolean skipHeaders) {
list<list> allFields = new List<List>();
// replace instances where a double quote begins a field containing a comma
// in this case you get a double quote followed by a doubled double quote
// do this for beginning and end of a field
contents = contents.replaceAll(‘,”””‘,’,”DBLQT’).replaceall(‘”””,’,’DBLQT”,’);
// now replace all remaining double quotes – do this so that we can reconstruct
// fields with commas inside assuming they begin and end with a double quote
contents = contents.replaceAll(‘””‘,’DBLQT’);// this is 19 th line of util class
// we are not attempting to handle fields with a newline inside of them
// so, split on newline to get the spreadsheet rows
// so, split on newline to get the spreadsheet rows
list lines=new list();
try {
lines = contents.split(‘\n’);
} catch (System.ListException e) {
System.debug(‘Limits exceeded? ‘+e.getMessage());
}
integer num=0;
for(string line :lines) {
// check for blank CSV lines (only commas)
if(line.replaceAll(‘,’,”).trim().length()==0)
[![System.LimitException Regex Too Complicated][1]][1]
Hi david ,
I am face Error :System.NullPointerException: Attempt to de-reference a null object: Trigger In below code
trigger CreateTaskWhenNewLeadGenerate on Lead (after insert) {
Set LdIdSet = new Set();
if(Trigger.isAfter && Trigger.isInsert) {
// for ( Lead Ld : Trigger.New ){
// }
List LdList = [ SELECT Id,Name,OwnerId,Company,Email, Phone,pi__comments__c,Leasing_agent__c,Create_Leasing_Call_Task__c,Lead_Property_Of_Interest__c FROM Lead WHERE Id IN : LdIdSet];
Map<Id,List> LIdLdListMap = new Map<Id,List>();
List insTskList;
Task newTsk ;
for ( BP_Property__c Prop:[Select Id,Name,IS_ACTIVE__c,Leasing_agent__c from BP_Property__c])
{
// LdList = LIdLdListMap.get(Prop) ;
for ( Lead Ld : Trigger.New ){
LdIdSet.add ( Ld.Id );
if ( Trigger.NewMap.get ( Ld.Id ).Create_Leasing_Call_Task__c && ! Ld.Create_Leasing_Call_Task__c ){
//Ld.Create_Leasing_Call_Task__c = true;
LdList = LIdLdListMap.get( Ld.Id ) ;
if ( LdList == null || LdList.size() == 0 )
continue;
if(Ld.Lead_Property_Of_Interest__c == null){
if(Ld.Leasing_Agent__c == null){
}
else{
newTsk = new Task();
newTsk.Subject = ‘PC-Leasing Call’;
newTsk.OwnerId = Ld.Id;
newTsk.Leasing_Agent_ID__c = ‘a0MG000000XkQFc’;
insTskList.add ( newTsk );
}
}
}else if(Ld.Lead_Property_Of_Interest__c != null && Ld.Leasing_Agent__c != null )
{ prop.IS_ACTIVE__c = true;
prop.Leasing_Agent__r.IS_ACTIVE__c = true;
}
else{
newTsk = new Task();
newTsk.Subject = ‘LAInitial-Leasing call’;
newTsk.OwnerId = Ld.Owner_ID__c;
newTsk.WhoId =Ld.Id ;
NewTsk.Leasing_Agent__c = Ld.Leasing_Agent__c ;
insTskList.add ( newTsk );
}
}
}
insert newTsk;
}
}
Check out this post!
https://www.sfdc99.com/2014/02/22/debug-your-code-with-system-debug/
Hi David,
With the inputs from SFDC99,got the job in salesforce.Now I am struggling to do the job,because i learned theory is different from practical.Please suggest me on this and do the needful.
Thanks,
Carle
David,
Please just use my initials or first name only and not my full name on my post before. Thank you!
No problem, fixed =)
Hi David,
I recently got my Adm201 and Dev401 certifications …. On my way to meeting your Certification challenge.
I homeschool my children and also do contract work. I am not sure my resume is doing it’s job as I pursue other contract work and I was wondering if you had the time to look at it and give me your impression/suggestions.
I have followed you suggestion on LinkedIn and have gotten inquiries from my profile…. but didn’t get a response when I submitted an application for a contract position.
Let me take a look at your resume and see if I have any suggestions Sophie =)
Email me @ sfdc99.mailbag@gmail.com!
Thanks David! I’m definitely out of my comfort zone
I want the answer for one question in how many ways we can deploy code from sandbox to production
you can use changeset, eclipse, ANT Tool.
3 ways
1. development
2. customization only sand box
3. full copy sand box
Hi David,
When making triggers, when it is ideal to make the trigger in the trigger section vs. making it in the apex class and calling that class from the trigger section?
-Chris
Always in the Apex class, if you understand what you’re doing!
If not, you can continue doing it in a trigger until you’re caught up. The benefits are there but they’re relatively minute =)
HI david ,
when am useing invocable annotation in apex class am getting this error ” Unknown annotation: Invocable Method”
please let me know why i am gettimg this error
Thanks&Regards]
Karthik.A.S
Probably better to ask this one on the official forums =)
Just check the version of your apex class. Make sure that the current apex class version supports the annotation.
Thanks David for all your effort and its gonna be a great Idea.