+ Start a Discussion
Ross SutherlandRoss Sutherland 

Hello,

Trying to create a row level formula that looks to see if any columns has a blank so I have something like, 

IF(ISBlank(fHCM2__Team_Member__c.fHCM2__Birth_Date__c),"Blank","Not Blank")   which is fine.

But I want to add OR so I want to include OR IF ,
fHCM2__Team_Member__c.fHCM2__Manager__c is blank
OR IF, FK_fHCM2__Employment__c.UDFEmployment_Detail__c is blank


FK_fHCM2__Employment__c.UDFEmployment_Detail__c   is a picklist field so not sure how to add that in also.

Any ideas?

Thank

Ross
 

Best Answer chosen by Ross Sutherland
CharuDuttCharuDutt
IF(IOR( ISBlank(fHCM2__Team_Member__c.fHCM2__Birth_Date__c),
ISBlank(fHCM2__Team_Member__c.fHCM2__Manager__c),
ISBlank(TEXT(FK_fHCM2__Employment__c.UDFEmployment_Detail__c)) ),"Blank","Not Blank")
Felix QuinonesFelix Quinones 

Hello All, 

I'm trying to create a formula field (Yearly Compliance) for a custom object named Compliance. The formula should add the compliance for the quarter (i.e. Q1_c__c), if not left blankand, and divide those by the number of complete fields. I'm trying to calculate the percent of compliance. The problem is that any of those four number fields could be left on black.

I tried the following formulas in where any of the Qs (i.e. Q1_c__c)  could be a number or could be left blank.

IF( 
AND 
   (Q1_c__c =0, 
    Q1_c__c = 0, 
    Q1_c__c = 0, 
   Q1_c__c = 0
    ),
    0, 
(Q1_c__c + Q2_c__c + Q3_c__c + Q4_c__c)/4)

 

IF(

AND(
ISBLANK(Q1_c__c),
ISBLANK(Q2_c__c),
ISBLANK(Q3_c__c),
ISBLANK(Q4_c__c)
),
NULL,(Q1_c__c + Q2_c__c + Q3_c__c + Q4_c__c)/4)

Here is a picture of the pay layout . 

  • If the quarter is left black, means that do not apply.
  • I'm trying to calculate the percent of Yearly Compliance. Here the Yearly Compliance should be 100% divided by 3. This is because the quarter empty (Q1) do not count for this year compliance. Also, the other two quarters are in 0%. 


Example
 

Yearly compliance should be 33.33%
Best Answer chosen by Felix Quinones
Swati PawarSwati Pawar
Hi,

Below mentioned formula might help you.  Make sure to check "Treat blank fields as blanks" option in your formula field.

Formula :
IF(
(Q1__c = 0 ||ISBLANK(Q1__c)) && (Q2__c = 0 || ISBLANK(Q2__c)) && (Q3__c = 0 || ISBLANK(Q3__c)) && (Q4__c = 0 || ISBLANK(Q4__c)) ,
0 ,
((IF(ISBLANK(Q1__c),0,Q1__c) +
IF(ISBLANK(Q2__c),0,Q2__c) +
IF(ISBLANK(Q3__c),0,Q3__c) +
IF(ISBLANK(Q4__c),0,Q4__c) ) )/ 
(IF(ISBLANK(Q1__c),0,1)+ IF(ISBLANK(Q2__c),0,1) +
IF(ISBLANK(Q3__c),0,1) + IF(ISBLANK(Q4__c),0,1))
 
)

User-added image


If it works for you then mark it as a best answer.

Thanks !!
RJ12RJ12 

I'm doing a REST API call to get the global value set and trying to deserialize the JSON result to get the picklist values in a List<String>.

Here is the JSON:

{
  "size": 1,
  "totalSize": 1,
  "done": true,
  "queryLocator": null,
  "entityTypeName": "GlobalValueSet",
  "records": [
    {
      "attributes": {
        "type": "GlobalValueSet",
        "url": "/services/data/v53.0/tooling/sobjects/GlobalValueSet/0Nt59000000AAAAAAA"
      },
      "Metadata": {
        "customValue": [
          {
            "color": null,
            "default": false,
            "description": null,
            "isActive": null,
            "label": "USA",
            "urls": null,
            "valueName": "USA"
          },
          {
            "color": null,
            "default": false,
            "description": null,
            "isActive": null,
            "label": "Canada",
            "urls": null,
            "valueName": "Canada"
          }
        ],
        "description": null,
        "masterLabel": "US States & Territories",
        "sorted": false,
        "urls": null
      },
      "Id": "0Nt59000000AAAAAAA"
    }
  ]
}
I need help in fixing the error and also how to get valueNames in a List<String>

Error: System.JSONException: Malformed JSON: Expected '{' at the beginning of an object.

Here is what I have tried so far:

Wrapper:
    public class GlobalValueSetWrapper{
        Metadata metadata;

    public class Metadata {
        public List<CustomValue> customValue;
    }
    
    public class CustomValue {
        public String label;  
        public String valueName;
    }
    }


Class:
//calling API to get the JSON result
HttpResponse res = GlobalValueSetAPIHandler.getResponse('Countries');
GlobalValueSetWrapper wrapper = (GlobalValueSetWrapper) JSON.deserialize(res.getBody(), GlobalValueSetWrapper.class);
Best Answer chosen by RJ12
RJ12RJ12

I'm able to fix it.

public class GlobalValueSetWrapper{
    public List<Records> records;

    public class Records {
        public Metadata metadata;
    }
    
    public class Metadata {
        public List<CustomValue> customValue;
    }

    public class CustomValue {
        public String label;
        public String valueName;    
    }

    public static List<String> getPicklistValues(HttpResponse response){
        List<String> picklistValues = new List<String>();
        
        GlobalValueSetWrapper wrapper = (GlobalValueSetWrapper) System.JSON.deserialize(response.getBody(), GlobalValueSetWrapper.class);
        
        for(GlobalValueSetWrapper.customValue value : wrapper.records[0].metadata.customValue){
            picklistValues.add(value.valueName);
        }
        system.debug('Piclist Values: ' + picklistValues);
        
        return picklistValues;
    }
}
Best Answer chosen by Mukesh Kumar 470
AbhinavAbhinav (Salesforce Developers) 
Does that user have Create access for case at profile level?

If you remove create access for user. New Button will be hidden.

Mark it as best answer if it helps.
LIM AI KHOONLIM AI KHOON 
Hi,

I have one scenario, which is 1 staff id cannot be duplicated. in the same year. For example
Staf ID 123 Year__c = 2021 [Accepted]
Staf ID 123 Year__c = 2022 [Accepted]
Staf ID 123 Year__c = 2022 [Not Accepted because already exist in 2022]. May I know how to do that using the validation rule?
 
not(isblank(vlookup( $ObjectType.Incentive__c.Fields.Id, $ObjectType.Incentive__c.Fields.Name,Name))) &&
Id <> vlookup( $ObjectType.Incentive__c.Fields.Id,$ObjectType.Incentive__c.Fields.Name, Name)
This is my current formula, but this does not work like how to suppose to.
 
Best Answer chosen by LIM AI KHOON
LIM AI KHOONLIM AI KHOON
https://focusonforce.com/configuration/preventing-duplicate-records-with-salesforce-config/
SFDC 13SFDC 13 
Here is the code but it won't work properly if I attached document in the notes and Attachment section then also it will throw an error. if any one know then please help me.
Code::  

trigger closeWonMustAttach on Opportunity (before insert, before update) {
  // Find all opportunities and their list of attachments...
  Map<Id,Opportunity> opportunityAttachments = new Map<Id,Opportunity>(
    [SELECT Id,(SELECT Id FROM Attachments) FROM Opportunity WHERE Id IN :Trigger.new]
  );
  // For each opportunity being created or modified...
  for(Opportunity opp:Trigger.new) {
    if(opp.StageName=='Closed Won' && // If it is changing to closed/won...
      (!opportunityAttachments.containsKey(opp.id) || // And the opportunity was not found (Insert)...
       opportunityAttachments.get(opp.id).Attachments == null || // Or the opportunity attachment list was null...
       opportunityAttachments.get(opp.id).Attachments.size()==0)) { // Or the attachment list has no entries...
      opp.StageName.addError('You must first attach a file to this opportunity before changing to Closed/Won.'); // So we prevent saving here.
    }
  }
}
Best Answer chosen by SFDC 13
agrawal mukulagrawal mukul
Code refactored :

set<Id> oppId=new set<Id>();
        for(Opportunity opp:newRecordList)
        {
            oppId.add(opp.Id);
        }
        
        Map<Id,ContentDocumentLink> opportunityAttachments = new Map<Id,ContentDocumentLink>();
        list<ContentDocumentLink> conList=[SELECT ContentDocumentId,LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId IN :oppId];
        for(ContentDocumentLink opp:conList)
        {
            opportunityAttachments.put(opp.LinkedEntityId,opp);
            
        }
        
       
        System.debug('opportunityAttachments'+ opportunityAttachments);
  // For each opportunity being created or modified...
  for(Opportunity opp:newRecordList) {
    if(opp.StageName=='Closed Won' && // If it is changing to closed/won...
      !opportunityAttachments.containsKey(opp.id)) { // Or the attachment list has no entries...
      opp.StageName.addError('You must first attach a file to this opportunity before changing to Closed/Won.'); // So we prevent saving here.
    }
  }
    }
Steve Houghtalen 2Steve Houghtalen 2 
When I try to set my domain, I get this error message
It looks like your network doesn’t allow you to access these domains.

    • https://d1i000003gqvcuac.my.salesforce.com
    • https://d1i000003gqvcuac--c.documentforce.com

 
Best Answer chosen by Steve Houghtalen 2
Steve Houghtalen 2Steve Houghtalen 2
When I went to set my domain, the subsequent screen looks like the attached. It appears that my domain got set, not sure how, perhaps by Salesforce.The only choice was to "Keep Current  Domain"  which didn't  make any sense.  The error messages and recommended actions also didn't make any sense. I clicked on "Keep Current Domain" and the following screen allowed you to name my domain.  Not exactly user friendly.User-added image
ColbridgeColbridge 
else if line is getting covered and is shown in blue/green, but the next two lines are in red. How to get that covered?
 
} else if ((checkedSummaryPlanIds == totalSummaryPlanIds) && (planIdMatch == false)) {
      skippedRecords += ddRecs.Plan_id__c + ' - ' + ddRecs.account_name__c + '\n'; // concatinated list of skipped records plan ids
      totalSkippedCtr++;
}

 
Best Answer chosen by Colbridge
AbhinavAbhinav (Salesforce Developers) 
that means its checking your condition if ((checkedSummaryPlanIds == totalSummaryPlanIds) && (planIdMatch == false))  but its not getting true so other two lines are not covered.

Add you test data in sych way that else if conditions evaluates to be true.

Thanks!
Ankita dixitAnkita dixit 
What is this type of error means: what is possible solution?
trigger ApexTrigger10 on Contact (After insert,After Delete) {
    
    set<id> contactSet = new set<id>();
    List<Account> newAccountList = new List<Account>();
    
    if(trigger.isInsert && trigger.isAfter){
        for(Contact con:trigger.new){
            contactSet.add(con.Account);
         }
    }

    if(trigger.isDelete && trigger.isAfter){
        for(Contact con:trigger.old){
            contactSet.add(con.Account);
         }
    }
    List<Account> Acc= [SELECT id, name,(SELECT id,name from contacts) FROM Account WHERE id IN:contactSet];
    for( Account a : Acc)
    {
        a.Total_number_of_contacts__c= a.contacts.size();
        newAccountList.add(a);
    }
    update newAccountList;
}
 
Best Answer chosen by Ankita dixit
Maharajan CMaharajan C
Hi Ankita,

You have reffered the Account Lookup Api name wrongly in below line so you are getting this error...

contactSet.add(con.Account);     ==>    contactSet.add(con.AccountId);

Please try the below code:
 
trigger ApexTrigger10 on Contact (After insert,After Delete) {
    
    set<id> contactSet = new set<id>();
    List<Account> newAccountList = new List<Account>();
    
    if(trigger.isInsert && trigger.isAfter){
        for(Contact con:trigger.new){
            contactSet.add(con.AccountId);
         }
    }

    if(trigger.isDelete && trigger.isAfter){
        for(Contact con:trigger.old){
            contactSet.add(con.AccountId);
         }
    }
    List<Account> Acc= [SELECT id, name,(SELECT id,name from contacts) FROM Account WHERE id IN:contactSet];
    for( Account a : Acc)
    {
        a.Total_number_of_contacts__c= a.contacts.size();
        newAccountList.add(a);
    }
	
	if(!newAccountList.isEmpty())
		update newAccountList;
}

Thanks,
Maharajan.C
Best Answer chosen by Chetan Awate
AbhinavAbhinav (Salesforce Developers) 
Please elaborate your post with related code snippet , use case .