You need to sign in to do that
Don't have an account?

How can I get the name of the current app in the Apex Controller?
public static String getAppName() { UserAppInfo userAppInfo = [SELECT Id, AppDefinitionId FROM UserAppInfo WHERE UserId = :UserInfo.getUserId() LIMIT 1]; AppDefinition appDefinition = [SELECT DurableId, Label FROM AppDefinition Where DurableId = :userAppInfo.AppDefinitionId LIMIT 1]; return appDefinition.Label; }But Im getting 3 errors:
Line 1: No such column 'AppDefinitionId' on entity 'UserAppInfo'
Line 2: Invalid type: AppDefinition
Line 3: Variable does not exist: appDefinition
Can anyone provide some insight as to what I may be doing wrong? Thanks!

what will be the soql query to find the no child account records related to specific account record in account object




https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html (https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html )
Basic Examples of SOQL RELATIONSHIPS:
Child > Parent (Standard Object)
Selectid,Account.Name,Account.Phone,Account.industry,Account.Type,Account.Rating,Account.website,Account.Ownership,Account.AnnualRevenue,Account.NumberOfEmployees,Account.CleanStatus from Contact
Child >Parent(Custom Object)
Selectid,COLLEGE__r.Name,COLLEGE__r.Contact__c,COLLEGE__r.Count__c,COLLEGE__r.Highest_Marks__c,COLLEGE__r.Address__cfrom Studnt__c
Parent >Child(Standard object)
select Name, Industry, (select AssistantName, Email from contacts)from ACCOUNT
Parent >Child (Custom Object)
1select id,Name,(select Studnt__c.name__c from Studnts__r) from College__C
For further reference check this,
https://developer.salesforce.com/forums/?id=906F00000009BgeIAE
If it helps you and closes your query by marking it as solved so that it can help others in the future.
Thanks.

Validation Rule Not Working as Expected suggestions?
Hello,
I am stuck on a validation rule -
If Sub Category is either 'Attestation Form Complete' or 'Attestation Form Incomeplete', all the other fields listed must not be blank.
The current formula will not let me create the record even if all the fields listed are completed. Any suggestions would be helpful.
Thanks!

There is a problem in your formula:
Please try the below one:
AND(OR( ISPICKVAL(Sub_Category__c,"Attestation Form Complete"), ISPICKVAL(Sub_Category__c,"Attestation Form InComplete") ), OR( ISPICKVAL(Creditable_Coverage__c,""), ISBLANK(Start_Date__c), ISBLANK(End_Date__c), ISPICKVAL(Type_of_Coverage__c,""), ISPICKVAL(Relationship_to_Member__c,""), ISPICKVAL(Verbal_Permission_Obtained__c,"") ))
Thanks,
Maharajan.C

<pre>
Integer loopCount = 0;
for ( Object obj : listOfObjects )
{
// do stuff here...
loopCount++;
}
</pre>

Try below Code in you Dev Console and see if this is what you are looking for. Basically reverse triangle logic is same in almost all OOP languages, it doesn't matter if it is Java or Apex all we are going to use is for loops!
String revTriangle = '';
Integer x = 1;
Integer y = 1;
for (x = 1; x <= 10; x++)
{
for (y = x; y <= 10; y++)
{
if (y<=x)
revTriangle +='*';
else
revTriangle+='*';
}
revTriangle+='\n';
}
System.debug('ReverserTriangle: \n' + revTriangle);
Thank you
getting picklist field options in list in apex classs
can i get all the values of a picklist field in a list some how?
I have picklist type custom field in the product. having some options.
In my apex class i want to use these options. can I get them some how throught code?

If you want to display pick list values in your custom page through dyanamic apex .You can check below link it will help .
https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html
If you want in a string array or list then you can use below code .
public List<String> getPickListValuesIntoList(){ List<String> pickListValuesList= new List<String>(); Schema.DescribeFieldResult fieldResult = ObjectApiName.FieldApiName.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry pickListVal : ple){ pickListValuesList.add(pickListVal.getLabel()); } return pickListValuesList; }Let us know if it helps !!
Thanks
Manoj

Apex Test Class Error
System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, Alias: data value too large: Sminull90 (max length=8): [Alias]
Below is my code:
Apex Class:
public class NewUtilStaffProcess {
@future
public static void createUtlUser(Id recid) {
Contact gcon = [SELECT Email, Lastname, Firstname, Middlename, AcctId
FROM Contact
WHERE Id = :recid];
Profile p = [SELECT Id FROM Profile WHERE Name='HAVNA City Public Utility Group'];
Id acctsTypeId = [SELECT Id
FROM RecordType
WHERE SObjectType = 'Account'
AND Name = 'Account Source'].Id;
String groleId = [SELECT Id FROM UserRole WHERE Name = 'Utility Staff' LIMIT 1].Id;
String formatUsrName;
String setUsrLoc;
Account retAcct = [SELECT Id, HAVNA_Country__r.HAVNA_Letter_Code__c, Hav_Locality__c, Hav_Street__c
FROM Account
WHERE Id = :gcon.AcctId
AND recordTypeId = :acctsTypeId
LIMIT 1];
if (retAcct.Hav_Street__c == 'Local/Surveyor')
setUsrLoc = retAcct.HAVNA_Country__r.HAVNA_Letter_Code__c+retAcct.Hav_Locality__c;
if (retAcct.Hav_Street__c == 'City/Surveyor')
setUsrLoc = retAcct.HAVNA_Country__r.HAVNA_Letter_Code__c+'C1';
if (retAcct.Hav_Street__c == 'State/Surveyor')
setUsrLoc = retAcct.HAVNA_Country__r.HAVNA_Letter_Code__c+'C2';
if (gcon.middlename == null) {
formatUsrName = gcon.Lastname.deleteWhitespace().toLowercase().trim()+'.'+gcon.Firstname.deleteWhitespace().toLowercase().trim()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
} else {
Integer midSize = gcon.Middlename.length();
if (midSize == 1) {
formatUsrName = gcon.Lastname.deleteWhitespace().toLowercase().trim()+'.'+gcon.Firstname.deleteWhitespace().toLowercase().trim()+'.'+gcon.middlename.deleteWhitespace().toLowercase().trim()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
} else {
formatUsrName = gcon.Lastname.deleteWhitespace().toLowercase().trim()+'.'+gcon.Firstname.deleteWhitespace().toLowercase().trim()+'.'+gcon.middlename.deleteWhitespace().trim().substring(0,1).toLowercase()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
}
}
System.debug('Formatted Username: '+formatUsrName);
User u = new User(Alias = gcon.Lastname.deleteWhitespace().trim().length() > 4 ? gcon.Lastname.deleteWhitespace().trim().substring(0,3)+setUsrLoc: gcon.lastname+setUsrLoc,
Email = gcon.Email,
EmailEncodingKey = 'UTF-8',
LastName = gcon.Lastname,
FirstName = gcon.Firstname,
MiddleName = gcon.Middlename,
LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US',
ProfileId = p.Id,
UserRoleId = groleid,
TimeZoneSidKey = 'America/New_York',
UserName = formatUsrName);
Insert(u);
System.debug(u.id);
UtilStaffPermSet.assgnPermissionSet(recId, u.Id);
System.resetPassword(u.Id, True);
}
}
Apex Test Class:
@isTest
public class NewUtilStaffProcessTest {
public static testMethod void InitialTest() {
/* Get Record Id Type */
Id conTypeId;
Id acctTypeId;
String formatUsrName;
String setUsrLoc;
conTypeId = [SELECT Id
FROM RecordType
WHERE SObjectType = 'Contact'
AND Name = 'Utility Staffer'].Id;
Id acctsTypeId = [SELECT Id
FROM RecordType
WHERE SObjectType = 'Account'
AND Name = 'Account Source'].Id;
Profile p = [SELECT Id FROM Profile WHERE Name='HAVNA City Public Utility Group'];
String groleId = [SELECT Id FROM UserRole WHERE Name = 'Utility Staff' LIMIT 1].Id;
Integer midsize;
//Create new State record; initialize required field(s), then insert
HAV_State_and_Country__c state = new HAV_State_and_Country__c();
state.Name = 'Oregon';
state.HAV_Letter_Code__c = 'OR';
state.HAV_Type__c = 'State';
Insert state;
//Create new Account record; initialize required field(s), then insert
Account acct = new Account(Name='Oregon Local 7');
acct.Hav_Locality__c = '90';
acct.Hav_Street__c = 'Local/Surveyor';
acct.RecordTypeId = AcctTypeId;
acct.HAV__Country__c = state.id;
insert acct;
//Create new Contact record; initialize required field(s), then insert
Contact con = new Contact();
con.FirstName = 'Ralph';
con.LastName = 'Smith';
con.Middlename = 'Otis';
con.RecordTypeId = conTypeId;
con.email = 'rsmith8@verizon.com';
con.AcctId = acct.id;
//Insert Contact
Insert con ;
System.debug(con.id);
Account retAcct = [SELECT Id, HAV_Country__r.HAV_Letter_Code__c, Hav_Locality__c, Hav_Street__c
FROM Account
WHERE Id = :con.AcctId
AND recordTypeId = :nomsTypeId
LIMIT 1];
if (retAcct.Hav_Street__c == 'Local/Surveyor')
setUsrLoc = retAcct.HAV_Country__r.HAV_Letter_Code__c+retAcct.Hav_Locality__c;
if (con.middlename == null) {
System.debug('3: '+setUsrLoc);
formatUsrName = con.Lastname.deleteWhitespace().toLowercase().trim()+'.'+con.Firstname.deleteWhitespace().toLowercase().trim()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
} else {
System.debug('4: '+setUsrLoc);
midSize = con.Middlename.length();
if (midSize == 1) {
System.debug('5: '+setUsrLoc);
formatUsrName = con.Lastname.deleteWhitespace().toLowercase().trim()+'.'+con.Firstname.deleteWhitespace().toLowercase().trim()+'.'+con.middlename.deleteWhitespace().toLowercase().trim()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
} else {
System.debug('6: '+setUsrLoc);
formatUsrName = con.Lastname.deleteWhitespace().toLowercase().trim()+'.'+con.Firstname.deleteWhitespace().toLowercase().trim()+'.'+con.middlename.deleteWhitespace().trim().substring(0,1).toLowercase()+'.cnastaff'+setUsrLoc+'@HAVNA.gmail';
}
}
User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
system.runAs(thisUser){
User u = new User(Alias = con.LastName.deleteWhitespace().trim().length() > 4 ? con.LastName.deleteWhitespace().trim().substring(0,4)+setUsrLoc: con.LastName+setUsrLoc,
Email = con.email,
EmailEncodingKey = 'UTF-8',
LastName = con.LastName,
FirstName = con.Firstname,
MiddleName = con.Middlename,
LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US',
ProfileId = p.Id,
UserRoleId = groleid,
TimeZoneSidKey = 'America/New_York',
UserName = formatUsrName);
Insert(u);
System.debug(u.id);
Test.startTest();
NewUtilStaffProcess.createUtlUser(con.id);
Test.stopTest();
system.debug('Done');
}
}
}
Thanks.

The User Alias field has default size limit which is Maximum 8 characters. But code generating more than 8 character (Sminull90).
Your code generating the alias dynamically so you have to handle the characters limit. And also avoid the null by using proper null check because am seeing null got genereated in alias Sminull90.
Alias = con.LastName.deleteWhitespace().trim().length() > 4 ? con.LastName.deleteWhitespace().trim().substring(0,4)+setUsrLoc: con.LastName+setUsrLoc
Thanks,
Maharajan.C

Difference between WhoId & WhatId on Task
On the task there is a WhatId and a WhoId. Sometimes the WhatId is filled in and others have the WhoId filled in. In which situations is one used over the other?
Thanks



WhoID refers to people things. So that would be typically a Lead ID or a Contact ID
WhatID refers to object type things. That would typically be an Account ID or an Opportunity ID

Subtract one minute from Current time
I’m newbie to Salesforce.
I would like to know the syntax “How to subtract one minute and two minutes from the current time”? I have checked in Datemethods in Apex documentation. No luck found.
Can anyone help?
Thanks



This will work:
For 1 minute: NOW() - (1/1440)
For 2 minutes: NOW() - (2/1440)
Thanks,
Pratik
P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
OpportunityShare and INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY : SOLVED
Problem statement:
When APEX inserting OpportunityShare records, you get DML Exception: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY
Why does this happen?
The obvious reasons are:
- OpportunityShare.OpportunityId is for an invalid Opportunity (or not an opportunity at all)
- Running user doesn't have access to the Opportunity in OpportunityId
But if neither of these are the case...what else could it be?
ANSWER:
You can not insert OpportunityShare records for the current owner of the record. You'll need to modify the Apex code to see if the current owner is the same as OpportunityShare.UserOrGroupId. If it is, then don't insert. You can still create OpportunityTeamMember records for that user but not OpportunityShare. Who the current user is will depend if you are doing the OpportunityShare Dml statement in a before trigger, after trigger, VF controller, or API.
Although I haven't tested this, I presume the above applies to AccountShare and CaseShare objects as well.


Greetings to you!
Your code looks good to me. Make sure you are using API version 43.0 or later. As per the Salesforce doc, AppDefinitionId field on UserAppInfo object and AppDefinition object are available in API version 43.0 and later.
Please refer to the below links which might help you further.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userappinfo.htm
https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_appdefinition.htm
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas