I have a class marked 'With Sharing' and a simple method to get all org wide emails to populate in a picklist on my page:  public String getOrgEmails(){     List&lt;OrgWideEmailAddress&gt; orgWideEmails = new List&lt;OrgWideEmailAddress&gt;();      orgWideEmails = [SELECT Id, Address, DisplayName FROM OrgWideEmailAddress LIMIT 50000];      return JSON.serialize(orgWideEmails); }   I had thought that when users set up org wide emails, and specified profiles who could access them, the query would only return org wide emails a user was profiled to have access to.   This is not the case. The query just returns all org wide emails. But, the org wide email address object is very limited and doesn't tell you what profiles have access to it.   Is there any way to actually limit the org wide emails returned by if the executing user has access to it based on profile permissions on the org wide email.   Salesforce is obviously capable of doing this check, which is why they let you set that up. But I cannot see how we are able to do this check in apex.
121096
I'd like to create a popup list on one of my Visualforce pages, for a user to select from a list of OrgWideEmailAddress records.  My goal is to limit the list to only those records that they're allowed to use.  I'm going to save the selection for use in later automatic emails.  Based on what I've read, I won't be able to send emails to certain OrgWideEmailAddresses:   The address hasn't been verified yet.  I don't see any fields in the schema that appear to show verification state. The address is only available to profiles that the user isn't a member of.  I don't see where the profile list is stored for each record.   Some of my problem could just be due to not understanding the standard objects so well, and perhaps there's a way to get at this through UserInfo, or by making my query on the User object which may have a child relationship to OrgWideEmailAddress since it's listed in the schema viewer of the Force.com IDE.  Here's the test code I'm working with:  for (OrgWideEmailAddress addr : [SELECT DisplayName, Address          FROM OrgWideEmailAddress ORDER BY DisplayName]) {     System.debug( addr.DisplayName + ' &lt;' + addr.Address + '&gt;'); }   I tried creating a new Messaging.SingleEmailMessage and then calling setOrgWideEmailAddressId() on it with each OrgWideEmailAddress Id, in hopes that invalid Ids would throw an exception, but to no avail.  My goal is to modify the test code to provide just the subset of records that the current user will be able to use.
122220
I've created a custom object for Leaves which allows the users under my org to apply for leaves. I've added three types of leaves such as Casual Leave, Sick Leave &amp; Leave without Pay. I've used an Apex Trigger to check and limit the creation of only one record by one user per day but this Apex is creating a problem in org because it isn't allowing the users to apply for pre-planned leaves, i.e. if a user is applying for Sick Leave for the day he/she should also be allowed to apply for other leaves like Casual &amp; Unpaid for different dates on the same day.   Fields I've used:    Start_Date__c (Date type) End_Date__c (Date type) Leave_Type__c (Picklist type)   I want to use a trigger dependent on the Start_Date__c &amp; Leave_Type__c  The Apex Currently in use:  trigger LeaveRecordDuplicateTrigger on New_Casual_Leave__c (before insert) {       for(New_Casual_Leave__c a:Trigger.new)        {         string uid = userinfo.getName();          List&lt;New_Casual_Leave__c&gt; acc=[select Id, CreatedDate, Contact__r.Account.Name,   Start_Date__c, Leave_Type__c from New_Casual_Leave__c where (Contact__r.Account.Name = :uid AND CreatedDate = TODAY)];              if(acc.size()&gt;0)              {                a.adderror('One leave is already applied for the Day For ' + uid);              }        }    }    Please help me out with this.
34418
I have a Sharepoint app and I use a caml query to filter the data I get back:      var caml = "&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;And&gt;&lt;Contains&gt;&lt;FieldRef Name='PublishingPageLayout' /&gt;&lt;Value Type='URL'&gt;" + pageLayoutName + "&lt;/Value&gt;&lt;/Contains&gt;&lt;Neq&gt;&lt;FieldRef Name='NewsCategory' /&gt;&lt;Value Type='Lookup'&gt;Memo mailer&lt;/Value&gt;&lt;/Neq&gt;&lt;/And&gt;&lt;/Where&gt;&lt;OrderBy&gt;&lt;FieldRef Name='Created' Ascending='False' /&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;";     var url = appWebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('pages')/GetItems@target='" + hostWebUrl + "'";     var requestData = '{"query": { "__metadata": { "type": "SP.CamlQuery" }, "ViewXml": "' + caml + '"}}';     return $.ajax({         url: url,         type: "POST",         data: requestData,         headers: {             "Accept": "application/json; odata=verbose",             "X-RequestDigest": formDigest,             "Content-Type": "application/json; odata=verbose"         },         dataType: "json"     });   This works and I get data back. Now the issue I have is that I'm not getting any lookup data back, I only get the ID's of the lookups I want. To accomplish this I have tried using oData combined with my caml query:  var url = appWebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('pages')/GetItems\?$select=*,Author/Title\&amp;$expand=Author\&amp;@target='" + hostWebUrl + "'";  var url = appWebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('pages')/GetItems?$select=*,Author/Title&amp;$expand=Author&amp;@target='" + hostWebUrl + "'";   This results in a bad request error:  {"error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The $expand query is not valid for field 'Author'."}}}   To overcome this error I removed my caml query and tried using a get request using odata $filter (I need to filter by the PublishingPageLayout field) $filter=substringof(PublishingPageLayout, "NewsLayout.aspx") But again I keep getting an error:  The field 'PublishingPageLayout' of type 'URL' cannot be used in the query filter expression.   I've had a look at oData and I think it only lets you filter on specific fields?  My question is how can I use caml and odata together to get back all of my data including my lookup fields in one call?  If I can't combine them both, is there another way using the rest api to get back all my data and all my lookup data?  I don't want to make other ajax calls to get the lookup data back as I have at least 5-6 lookup fields on each item I'm querying against and I don't want to make 6 more ajax calls just to get all my data back!  Thanks for any input.
17069
We are a team with three orgs. Development, UAT and Production.  We are trying to move away from changesets and manual copying and use various deploy mechanisms or scratch orgs but we cannot deploy org wide email addresses since it is not supported in the metadata api.   The problem is that since addresses cannot be deployed, workflows referencing them cannot either. And if we dont deploy all workflows some tests will fail and the environment will be wrong.  I would appreciate any help with this issue, thanks
44088
We have a org wide email addressed which has been "Verified" into our sandbox. I understant org wide email addressed is unsupported metadata, so this was achieved as pre deployment step.   Into our repo, we have a workflow that send email alert to that org wide email address. "  Workflow   ... &lt;senderAddress&gt;noreply@mycompany.com.au&lt;/senderAddress&gt; &lt;senderType&gt;OrgWideEmailAddress&lt;/senderType&gt;    The problem we are facing is that we are still getting the following error even if this org wide email address is verified:      You must specify a verified Org Wide Email Address for this sender   type.   Is that a bug in the metadata api or expected behaviour ? Ideally we would like to not have to do that as a post deployment step.   PS: We are running DX under api version 43.0
11317
Can we query the info from "Data Management -> Storage Usage" through SOAP API? If so how? Actually, I need the count of records in all the objects in the org, and the size. (Also would like to know how the size [in KBs] is calculated for a record ?)  **Edited**  Am actually looking for something like this :- Like for ex (C# code) :-  String[] SOQLS;  SOQLS[1] = "Select count(id) from accounts";  SOQLS[2] = "Select count(id) from contacts";  QueryResult[] qrarray = binding.query(SOQLS[]);  would I be able do something like this so that i can pull the count of all the objects through api (partner wsdl)?
104629
I am querying a list to return only items matching a certain title, but the query returns all items. It seems I built or execute the query the wrong way:  /* SP is an alias for Microsoft.SharePoint.Client SP = using Microsoft.SharePoint.Client */ var list = clientContext.Web.Lists.GetByTitle(listTitle);   SP.CamlQuery query = new SP.CamlQuery();  string qs = String.Format("&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=\"Title\"&gt;&lt;/FieldRef&gt;&lt;Value Type=\"Text\"&gt;{0}&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;", listItemTitle);  query.ViewXml = qs;   SP.ListItemCollection oCol = list.GetItems(query);  clientContext.Load(oCol);  clientContext.ExecuteQuery();  SP.ListItem item = oCol[0];   clientContext.Load(item, i =&gt; i.File);  clientContext.ExecuteQuery();   Based on the query oCol should only contain 1 Item, since the titles are definitly unique, but it returns 58 results (all items) and therefor the item at oCol[0] is not the correct one.  Please note: I was getting the Item and file by Id before, but the client wants a way to enter an error-prone string, so I need to use CAML.  How can I correct this?
49852
Profile has a setting "Modify All Data". How can we access "Modify All Data" in apex and in which object it is stored.
123171
I am getting an attachment via a Salesforce email service and in the Email service apex class logic, I query the user object by the email from address and set the ContentVersion owner as the user coming from the Query.  I am getting this error while performing this operation.  INVALID_STATUS, Documents in a user's private library must always be owned by that user.: [OwnerId]  Here is my code :  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {          Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();          //Get users for the incoming email address and also community user         List&lt;User&gt; lstUsersFromCommunity = [SELECT Id                                              FROM User                                              WHERE Profile.UserLicense.Name = 'Partner Community';                                             AND Email =: email.fromAddress];          //Process only if the incoming email address is belongs to a valid community user         if(lstUsersFromCommunity.size() &gt; 0){             //Get the user from the results list             User user = lstUsersFromCommunity.get(0);             try{                 //Create a list of ContentVersion to store new ContentVersion records                 List&lt;ContentVersion&gt; lstVersion = new List&lt;ContentVersion&gt;();                  //Iterate over the incoming email attachments                 for (Messaging.Inboundemail.BinaryAttachment binaryAttachment : email.binaryAttachments) {                     //New ContentVersion record                     ContentVersion newContentVersion = new ContentVersion();                     newContentVersion.versionData = binaryAttachment.body;                     newContentVersion.OwnerId = user.Id;                     newContentVersion.ContentLocation = 'S';                     newContentVersion.SharingOption = 'A';                     newContentVersion.Origin = 'H';                     newContentVersion.title = email.subject;                     newContentVersion.pathOnClient = binaryAttachment.fileName;                     lstVersion.Add(newContentVersion);                 }                 insert lstVersion;             }catch(Exception ex){                 System.debug('### EXCEPTION :  ' + ex.getLineNumber() + ' : ' + ex.getMessage());             }         }else{             //No user in for the from email address         }          return result;     }
47401
I Want to prevernt user to access other user cases in search and report as well in salesforce, when user at same level in role hierarchy.  My Organization-Wide Defaults setting is following   Case: Private User: Public Read Only Account, Contract and Asset: Private   Kinldy sugget the way, how can I achieve this.
65829
I have a list of accounts that I would like to perform a LIKE query on. Ideally, my query would be something like:  SELECT id, owner.name FROM Account WHERE name LIKE IN :entityList   Is there any way I can do this?  The issue is that my entity names come from a third party source, which means that small variations in name may be present, i.e     "Bay Ridge apt." VS "Bay Ridge Apartments"   It's hard to predict where the difference in spelling might be, and I was hoping that the LIKE filter might be some magical filter that can figure this out for me and match on a substring (i.e. "Bay Ridge").  The Salesforce guide doesn't include this option in their guide, so it might not be possible to combine a LIKE and an IN. Maybe there's a solution around it?  Maybe there's a way to perform a SOSL query on a list? Something like :     Find {entityList} In Account   I can't seem to find this any where...  Any guidance?  EDIT: It seems that it's not really possible to 'bulkify' SOSL queries. I could have ran a loop, but this would have hit governor limits. Using the LIKE filter with strategic wildcards was key.
119884
I have a list with a people column called AssignedTo.  I'm making a rest call:  .../_api/web/Lists/GetByTitle('listname')/Items?$expand=AssignedTo&amp;$select=*,AssignedTo/Title   Which is successfully returning the name of the person the item was assigned to. I'm trying to get other user information like email or their user id.  Most tutorials online show how to expand ID and Title (Name) and  I found a list of these properties that can be expanded:   ID FirstName LastName Title Department SipAddress   And those all work. But I can't find the email and or the login ID. I've tried $select=AssignedTo/LoginName and several other variations on that, but they all return that the field is not valid. I was hoping $select=AssignedTo/* would expand all the fields, but that doesn't rework either.  Anyone know if the above are the only fields that can be expanded off a people column?
67950
I just noticed that the return list for results is limited to 1000. I have more than 1000 groups in my domain (HUGE domain). How can I get more than 1000 records? Can I start at a later record? Can I cut it up into multiple searches?  Here is my query:  DirectoryEntry dirEnt = new DirectoryEntry("LDAP://dhuba1kwtn004"); string[] loadProps = new string[] { "cn", "samaccountname", "name", "distinguishedname" }; DirectorySearcher srch = new DirectorySearcher(dirEnt, "(objectClass=Group)", loadProps); var results = srch.FindAll();   I have tried to set srch.SizeLimit = 2000;, but that doesn't seem to work. Any ideas?
17780
I am running this script from developer console.  List&lt;Account&gt; lstAccount = [SELECT Id, Name, BillingStreet From Account LIMIT 1]; System.debug(lstAccount);   Debug Log:     23:47:04:012 USER_DEBUG [5]|DEBUG|(Account:{Id=0019000001nNLGEAA4, Name=Acct_nm001, BillingStreet=xyz Road, RecordTypeId=01290000000iaNiAAI})   I never queried for RecordtypeId in SOQL, but it is included in the list.  Although, if I run the query from the query editor, it is not showing RecordtypeId column.   Is this by design? Then why not Salesforce is not providing us audit fields in the first scenario.
9803
This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, navigate to the  tag. This question and answer is owned by the community! If you can improve it and make it more useful, you're welcome to edit it. I have a collection of records, like a List&lt;sObject&gt; or the Trigger.new context variable. I need to query other records that are related to these records either directly or indirectly, and I want to use the related data to make further updates. When I write a query in a loop, like for (Account a : Trigger.new) {     Account parent = [SELECT Name FROM Account WHERE Id = :a.ParentId];     // ... }  I keep hitting Salesforce query limits, and I know this is not best practice. What can I do to avoid this problem and bulkify my code?
108761
We are using SharePoint Online. I am planning to add a flow to send out an email notification whenever a new page is added to the site.   To do that, I need the list of members of that site cause I don't want to send it to everyone or anyone.   I am unable to retrieve the group members through REST API. When I fire the following REST call, I am getting the response as follows, but not the actual members and their email addresses  https://dhdigitalcoin.sharepoint.com/sites/OpenSourceTechTalk/_api/web/sitegroups/getbyname('Open%20Source%20Tech%20Talk%20Members')/users   &lt;entry&gt; &lt;id&gt;https://dhdigitalcoin.sharepoint.com/sites/OpenSourceTechTalk/_api/Web/GetUserById(7)&lt;/id&gt; &lt;category term="SP.User" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/&gt; &lt;link rel="edit" href="Web/GetUserById(7)"/&gt; &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Alerts" type="application/atom+xml;type=feed" title="Alerts" href="Web/GetUserById(7)/Alerts"/&gt; &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Groups" type="application/atom+xml;type=feed" title="Groups" href="Web/GetUserById(7)/Groups"/&gt; &lt;title/&gt; &lt;updated&gt;2019-06-03T12:47:56Z&lt;/updated&gt; &lt;author&gt; &lt;name/&gt; &lt;/author&gt; &lt;content type="application/xml"&gt; &lt;m:properties&gt; &lt;d:Id m:type="Edm.Int32"&gt;7&lt;/d:Id&gt; &lt;d:IsHiddenInUI m:type="Edm.Boolean"&gt;false&lt;/d:IsHiddenInUI&gt; &lt;d:LoginName&gt;c:0o.c|federateddirectoryclaimprovider|92b9f118-885e-4c23-a103-de7ce46d7421&lt;/d:LoginName&gt; &lt;d:Title&gt;Open Source Tech Talk Members&lt;/d:Title&gt; &lt;d:PrincipalType m:type="Edm.Int32"&gt;4&lt;/d:PrincipalType&gt; &lt;d:Email&gt;OpenSourceTechTalk@xxx.onmicrosoft.com&lt;/d:Email&gt; &lt;d:Expiration/&gt; &lt;d:IsEmailAuthenticationGuestUser m:type="Edm.Boolean"&gt;false&lt;/d:IsEmailAuthenticationGuestUser&gt; &lt;d:IsShareByEmailGuestUser m:type="Edm.Boolean"&gt;false&lt;/d:IsShareByEmailGuestUser&gt; &lt;d:IsSiteAdmin m:type="Edm.Boolean"&gt;false&lt;/d:IsSiteAdmin&gt; &lt;d:UserId m:null="true"/&gt; &lt;d:UserPrincipalName m:null="true"/&gt; &lt;/m:properties&gt; &lt;/content&gt; &lt;/entry&gt;   Is there a way I can retrieve the actual members?  Am I taking the right approach towards building email notifications?
19184
I need to send dynamic email to all my booking contacts using AMP Script. Using FOR loop makes repetitive content. I am pulling contacts from Salesforce reports directly without using Salesforce Data Extension.  1) Any way to display content respective to each record (Dynamically)  2) Can we directly get Opportunity columns present in  SF reports to Normal Data Extension? Like we can do for Contact,Account &amp; Leads  3) Any way to uniquely identify each opportunity records?  AMP Script:  %%[ Var@fname,@AccountName,@PictureDay,@AccountPhone,@BookingOwner,@BookingOwnerEmail,@bookingdetail,@Accountid Set @Accountid = AccountId Set @fname=FirstName Set @AccountName=AccountName Set @AccountPhone=Account:Phone Set @bookingdetail = RetrieveSalesforceObjects("Opportunity","Picture_Day__c,OwnerName__c,OwnerEmail__c","Picture_Day__c","=","2016-06-25","CloseDate","!=","2015-10-03") For @i=1 TO RowCount(@bookingdetail) DO Set @limitRow = Row(@bookingdetail, @i) Set @PictureDay = Field(@limitRow,'Picture_Day__c') Set @Bookingowner = Field(@limitRow,'OwnerName__c') Set @BookingOwnerEmail = Field (@limitRow,'OwnerEmail__c') ]%%  Dear %%=v(@fname)=%%,  We are looking forward to taking photographs at %%=v(@AccountName)=%% on %%=v(@PictureDay)=%%.The phone number we have on file for you is %%=v(@AccountPhone)=%%.  Your Account Manager is %%=v(@Bookingowner)=%% and you can reach them at %%=v(@BookingOwnerEmail)=%%. %%[NEXT @i]%%   Thanks,  Mitesh