• Boss Coffee
  • SMARTIE
  • 515 Points
  • Member since 2019
  • Salesforce Developer

  • Chatter
    Feed
  • 17
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 137
    Replies
Attempting to access the variables MIlestone1_Project__c has a Lookup relationship to Account with relationship name: `Projects__r'.
 
List<Account> accList = [SELECT Id, Name, EHR_Status__c, PM_Status__c,
                                    Project_Imp_Status__c, Other_Status__c,(select Client_Advisor_Email__c,
                                                                                 Resource_Coordinator_Email__c
                                                                                 from Projects__r) 

                             FROM Account
                             WHERE Id IN :AcctIds];
 
List<String> emailAdds = new List<String>();
                 for (Account al: accList) {
                    emailAdds.add(al.Projects__r.Client_Advisor_Email__c);
                    emailAdds.add(al.Projectss__r.Resource_Coordinator_Email__c); 
                 }



Any help is greatly appreciated.
 
Hi, 
I have n object student, which has two fields Completed Course(Text) and Course requested(pick List)
User-added image

I have a trigger which update the Completed course field automatically.......
My requirement is to restrict Any user from Editing the Completed Course field manually.
I tried to make this field 'Read Only' , but System Admin Still can edit the record manually.

is there any way such that Completed couse field gets updated only by trigger and nothing else?


Thank you
 


Hi, I have this error on my code:

 

public class Search_For_User
{
    String keyword;

    List<user>results = new List<user>();
    
    public String getkeyword(){
    return keyword;
    }
   
    public List<user> getresults(){
    return results;
    }
    
    public void setkeyword(String input){
    keyword = input;
    }
    
    public PageReference searchUser(){
    results = (List<User>)[FIND :keyword IN NAME FIELDS RETURNING USER(FirstName, LastName, ProfileId)][0];
    return null;
 
    }

     System.debug(results);
 
    
}
Can someone help me please...
I am making a custom aura component for a home page, and I would like to display what step along a path that particular project is at (ie. Pending Approval, Approved, In-Progress, Complete). However, I just can't find in the documentation what the path attribute is that I should include in my query in order to get  it's status. Thanks!
I am working on trigger which will populate a number field based on parent record.

For each parent record, child will have auto number

I have two objects which are having lookup relationship.
1) Build_Cycle__c
2) Action_Item__c
Auto number is working fine on creation but on deleting my trigger is not working.
lets say for one build cycle I have 4 action items
BUILD CYCLE:1
1) Actionitem1
2) Actionitem2
3) Actionitem3
4) Actionitem4

I tried below code which is not working if there are child existing records where auto numberfield is null rest everything is working perfectly.

my code is below, can anyone help me out in this issue.
 
public class RenameActionItem {
    public static void renameActionItemRecord(List<Action_Item__c> actionItemList){
        try{
            //Set to store the buildcycleid from action item
            Set<Id> buildCycleId = new Set<Id>();
            for(Action_Item__c actionObj : actionItemList) {
                buildCycleId.add(actionObj.DCS_Build_Cycle__c);   
            }  
            
            //Fetch action items that are related to buildcycleid
            List<Action_Item__c> actionItemList2 = new List<Action_Item__c>();
            actionItemList2 = [SELECT Id FROM Action_Item__c WHERE DCS_Build_Cycle__r.Id IN :buildCycleId]; 
            
            //Fetching Action item records in descending order to catch the highest Auto Number
            List<Build_Cycle__c> buildCycleList = new List<Build_Cycle__c>();
            buildCycleList = [SELECT Name, (SELECT Id, DCS_Auto_Number__c FROM Action_Items__r order by DCS_Auto_Number__c desc limit 1) FROM Build_Cycle__c WHERE Id IN: buildCycleId];
            
            for(Build_Cycle__c bObj : buildCycleList){
                //if existing records have DCS_Auto_Number__c == null then setting it to 1 using custom label
                integer length = integer.valueOf(Label.Auto_Number);
               try{
                    length = integer.valueOf(bObj.Action_Items__r[0].DCS_Auto_Number__c);
                }catch(exception e){
                }
                for(Action_Item__c cObj : actionItemList){
                    if(bObj.Id == cObj.DCS_Build_Cycle__c){
                            length++;
                            cObj.DCS_Auto_Number__c = length;
                    }
                }
                    
            }
       }catch(Exception e){
            System.debug('Exception in code'+e.getCause() + 'Exception in Line number'+e.getLineNumber());
       }
    }
}

 
I had to adjust a formula for one of my formula fields. However, I also have a field that is set to match the value of the formula field. The field is set via process builder.
 
After I updated the formula, the second field only updates after an update. (Edit => Save)
 
Is there any way I can perform this action (Edit => Save) on all Opportunities at once?
I created a trigger on case. Member_ID__c is a auto-number field on contact object. I am trying to find out repeat cases logged by a contact using custom checkbox Repeat_Caller__c on case. There are many other conditions, but I removed them in this code for simplicity. I am not able to match Member_ID__c field in cases even though multiple cases are created by the same contact. In other words, I am not able to enter the IF condition. I have pasted the trigger below.

Please guide me as to where the problem might be. Any help is appreciated.

 
trigger repeatCase1 on Case (before insert,before update) {
    List<Case> caseList = trigger.new;   
    Set<id> memberIdSet = new set<id>();
    for(case c: caseList){
        memberIdSet.add(c.Contact.Member_ID__c);
    }
      List<Case> allcase = [select Contact.Member_ID__c from case where contact.Member_ID__c IN: memberIdSet];               
      for(Case cs: caseList ){  
        for(Case all: allcase ){ 
            if(cs.contact.Member_ID__c == all.contact.Member_ID__c ){
                    cs.Repeat_Caller__c=True;
            }
        }
    }
    
}
hi, the following code creates a csv and sends it attached by email. When I paste this into dev console and execute, it works perfectly.
However, I need to create this as a class and process via a process builder and pass 3 variables of information to the class; strEmailTo, strPhone and strTreatment. I'm not sure how to do this. Any help much appreciated thanks.

string header = 'Telephone;Content \n';
string finalstr = header ;
string mStr;
string strPhone;
string strDate;
string strEmailTo;
string strTreatment;

strDate = '01/09/2019';
strPhone = '12345678';
strEmailTo = 'me@me.com';
strTreatment = 'test123';

mStr='Hi, your '+strTreatment+ ' treatment is scheduled for '+strDate ;

string recordString = +strphone+';'+mstr+'\n';
finalstr = finalstr +recordString;
  
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();

blob csvBlob = Blob.valueOf(finalstr);
string csvname= 'custom.csv';
csvAttc.setFileName(csvname);
csvAttc.setBody(csvBlob);

Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();

String[] toAddresses = new list<string> {strEmailTo};
String subject ='Visit';

email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setPlainTextBody('%Content%');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
I have the following scenario. I want to populate the highest price and the name of the company with the highest price. The name of the competitor populate but i am struggling to populate the corresponding price. Code below;

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    for (Opportunity opp :Trigger.new) {
        List <Decimal> competitorPrice = new List <Decimal> ();
        
        //Add all of our prices in a list in order of competitor
        competitorPrice.add (opp.Competitor_1_Price__c);
        competitorPrice.add (opp.Competitor_2_Price__c);
        competitorPrice.add (opp.Competitor_3_Price__c);
        
        //Add all our competitors in a list in order
        
        List <String> competitors = new List <string> ();
        competitors.add (opp.Competitor_1__c);
        competitors.add (opp.Competitor_2__c);
        competitors.add (opp.Competitor_3__c);
        
        //Loop through all the competitor to find the highest price
        
        Decimal highestPrice;
        Integer highestPricePosition;
        for (Integer i = 0; i > competitorPrice.size();i++) {
            Decimal currentPrice = competitorPrice.get(i);
            if (highestPrice == null || currentPrice > highestPrice) {
          
                
                highestPrice = currentPrice;
                highestPricePosition = i;
            }
            
            
        }
        
        //Populate the leading competitor with the competitor matching the highest price position& populate the corresponding price of the competitor
        opp.Leading_Competitor__c = competitors.get(highestPricePosition);
        opp.Leading_Competitor_Price__c = competitorPrice.get (highestPricePosition);
        
    }

}
 

trigger updateAssessmentValue on Assessment__c(after insert, after update) {
  Map<ID, Building__c> parentBuild = new Map<ID, Building__c>(); 
  List<Id> listIds = new List<Id>();

  for (Assessment__c childObj : Trigger.new){
    listIds.add(childObj.Building__c);
  }

  
  parentBuild = new Map<Id, Building__c>([SELECT id, Recent_Assessment_Date__c ,Recent_Assessment_Value__c ,(SELECT ID, Assessment_Value__c,Assessment_Date__c FROM Assessments__r) FROM Building__c WHERE ID IN :listIds]);

  for (Assessment__c assess : Trigger.new){
     Building__c myBuild = parentBuild.get(assess.Building__c);
     myBuild.Recent_Assessment_Date__c = assess.Assessment_Date__c ;
     myBuild.Recent_Assessment_Value__c = assess.Assessment_Value__c;
  }

  update parentBuild.values();
}
Hi,

I have created following APEX TRIGGER so that whenever a new job is created on SalesForce, a Task is created on JIRA CORE.

trigger JobTrigger on Contract (after insert, after update) {
    if (Trigger.isInsert && Trigger.isAfter) {
        JCFS.API.createJiraIssue('10000', '10100');
    }
    if (Trigger.isUpdate && Trigger.isAfter) {
        JCFS.API.pushUpdatesToJira();
    }
}

Now when I deploy this trigger from Sandbox to Production, I get following error:

Code Coverage Failure
Your organization's code coverage is 0%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
- JobTrigger

So can anyone help me how can I resolve this error that I can deploy this trigger to Production from Sandbox without any error?

Thanks,
Nitin.
Hi guys,

I have created a trigger on the OpportunityLineItemSchedule record to update fields in the parent OpportunityLineItem record. However it is not updating the fields in the OpportunityLineItem to blank values if I delete a scedule. Can anyone help me with this?

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    
    // UPDATED: Must handle multiple children for a single parent
    // Instead of a single OpportunityLineItem, hold a list of them
    Map<Id,List<OpportunityLineItemSchedule>> MapMonths = new Map<Id, List<OpportunityLineItemSchedule>>();
    
    // Have a temp list ready for looping
    List<OpportunityLineItemSchedule> tempOlisList;
    
    // Now populate the months map
    for(OpportunityLineItemSchedule sch : trigger.new) {
        // Check if the map already has an entry for the parent Id (key)
        if(MapMonths.containsKey(sch.OpportunityLineItemId)) {
            // If it does, then update the list with the new value (so it will not override the previous value)
            tempOlisList = MapMonths.get(sch.OpportunityLineItemId);
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        } else {
            // Otherwise, we will create a new entry in the map with a list value of just the current iteration's OLIS
            tempOlisList = new List<OpportunityLineItemSchedule>();
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        }
    }

    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
    for(OpportunityLineItem oli:[
        Select id, January__c,February__c, March__c, April__c, May__c, June__c, July__c, August__c, September__c, October__c, November__c,December__c 
        From OpportunityLineItem 
        Where Id IN :MapMonths.Keyset()
    ]) {
        // Then, the following is the updated if statement inside your for loop
        if(MapMonths.containsKey(oli.id)) {
            
            // UPDATE: Because we have a list of children now, we will need to loop through all of them to assign values to each month before moving on to the next Opportunity Line Item
            // Create a for loop to go through the list of children
            for(OpportunityLineItemSchedule olis : MapMonths.get(oli.id)) {
                
                // Create a switch statement to check what value is the Month
                switch on olis.Month__c {
                    // If the opportunity line item schedule's Month field was January
                    when 'January' {
                        // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
                        oli.January__c = olis.Quantity;
                    }
                    when 'February' {
                        oli.February__c = olis.Quantity;
                    }
                    when 'March' {
                        oli.March__c = olis.Quantity;
                    }
                    when 'Apr' {
                        oli.April__c = olis.Quantity;
                    }
                    when 'May' {
                        oli.May__c = olis.Quantity;
                    }
                    when 'June' {
                        oli.June__c = olis.Quantity;
                    }
                    when 'July' {
                        oli.July__c = olis.Quantity;
                    }
                    when 'August' {
                        oli.August__c = olis.Quantity;
                    }
                    when 'September' {
                        oli.September__c = olis.Quantity;
                    }
                    when 'October' {
                        oli.October__c = olis.Quantity;
                    }
                    when 'November' {
                        oli.November__c = olis.Quantity;
                    }
                    when 'December' {
                        oli.December__c = olis.Quantity;
                    }
                    // If it did not find any matches
                    when else {
                        // EDIT: do not put anything here for now
                        // You can leave this empty or put something in here to handle cases where the Month field is NOT the name of the month
                        // e.g. Month field was for some reason populated with 'Apple'
                    }
                }
            }
            OppLineItemList.add(oli);
        }
    }
    update OppLineItemList;
}
trigger contupdate on Container__c (before update) {
    try{
    list<string> FPOName = new list<string>();
    String fnames='';
 
    for(Container__c currentCont : trigger.new){
  
        list<ICCWorkbench__c> getRelatedFPO = [Select Id,Name,Container_Name__r.Name,Bill_Lading__r.ZAC_PO__c  from ICCWorkbench__c where Container_Name__r.Name = : currentCont.Name];
        for(ICCWorkbench__c IccWb : getRelatedFPO){
    
            FPOName.add(IccWb.Name);
            fnames=fnames+IccWb.Name+',';
    
        }
            currentCont.ZAC_Purchase_order_Number__c =  String.join(FPOName,',');
         // currentCont.BOL_ID__r.ZAC_PO__c = currentCont.ZAC_Purchase_order_Number__c ;
 
            
            system.debug('FPOName-->'+ FPOName);
        
        Bill_Of_Lading__c bolObj=[Select Id,Name,ZAC_PO__c from Bill_Of_Lading__c where id = : currentCont.BOL_ID__c ];
        bolObj.ZAC_PO__c=fnames;
        update bolObj;
        
    }
    }
    
        catch(exception e){
            system.debug('Exception throw ->' + e.getMessage());
            
        }
  

}

test class

@isTest(SeeAlldata=true)
public class testcontainerupdate {
    testmethod static void  testfn(){
    Bill_Of_Lading__c bol = new Bill_Of_Lading__c();
   bol.CurrencyIsoCode ='EUR';
    bol.Name='kekekek';
    bol.ZAC_PO__c='testing,myfpo';
        bol.ZAC_PO__c = 'test,test2';
    insert bol;
        
        bol.Name='zaccc';
        bol.ZAC_PO__c='11111';
        update bol;
        

   
    ICCWorkbench__c wcb  = new ICCWorkbench__c();
    wcb.name ='test';
    wcb.Bill_Lading__c=bol.Id;
    wcb.CurrencyIsoCode='EUR';
   // wcb.Container_Name__c=cont.id;
    insert wcb;
        
      wcb.name='finaltest,suraj,sam';
        update wcb;

    
  
    Container__c cont  = new Container__c();
    cont.name ='bolcont2';
    
     cont.ZAC_Purchase_order_Number__c='testing,myfpo,1111';
    insert cont;
      cont.name ='bolcont3';
       cont.ZAC_Purchase_order_Number__c='testing,myfpo,11111';
       cont.Bill_Of_Lading_Number__c='fire';
    //   cont.
       
       update cont;
      
    }
}

line not cover


            FPOName.add(IccWb.Name);
            fnames=fnames+IccWb.Name+',';

and

bolObj.ZAC_PO__c=fnames;
        update bolObj;
from above class
Hi guys, 

I have built my first trigger with the help of this group. I'm hoping someone can help me out building a test class for it so that I can deploy it into production. The trigger basically maps fields from OppLineItemSchedule to the OppLineItem

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    
    // UPDATED: Must handle multiple children for a single parent
    // Instead of a single OpportunityLineItem, hold a list of them
    Map<Id,List<OpportunityLineItemSchedule>> MapMonths = new Map<Id, List<OpportunityLineItemSchedule>>();
    
    // Have a temp list ready for looping
    List<OpportunityLineItemSchedule> tempOlisList;
    
    // Now populate the months map
    for(OpportunityLineItemSchedule sch : trigger.new) {
        // Check if the map already has an entry for the parent Id (key)
        if(MapMonths.containsKey(sch.OpportunityLineItemId)) {
            // If it does, then update the list with the new value (so it will not override the previous value)
            tempOlisList = MapMonths.get(sch.OpportunityLineItemId);
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        } else {
            // Otherwise, we will create a new entry in the map with a list value of just the current iteration's OLIS
            tempOlisList = new List<OpportunityLineItemSchedule>();
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        }
    }

    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
    for(OpportunityLineItem oli:[
        Select id, January__c,February__c, March__c, April__c, May__c, June__c, July__c, August__c, September__c, October__c, November__c,December__c 
        From OpportunityLineItem 
        Where Id IN :MapMonths.Keyset()
    ]) {
        // Then, the following is the updated if statement inside your for loop
        if(MapMonths.containsKey(oli.id)) {
            
            // UPDATE: Because we have a list of children now, we will need to loop through all of them to assign values to each month before moving on to the next Opportunity Line Item
            // Create a for loop to go through the list of children
            for(OpportunityLineItemSchedule olis : MapMonths.get(oli.id)) {
                
                // Create a switch statement to check what value is the Month
                switch on olis.Month__c {
                    // If the opportunity line item schedule's Month field was January
                    when 'January' {
                        // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
                        oli.January__c = olis.Quantity;
                    }
                    when 'February' {
                        oli.February__c = olis.Quantity;
                    }
                    when 'March' {
                        oli.March__c = olis.Quantity;
                    }
                    when 'Apr' {
                        oli.April__c = olis.Quantity;
                    }
                    when 'May' {
                        oli.May__c = olis.Quantity;
                    }
                    when 'June' {
                        oli.June__c = olis.Quantity;
                    }
                    when 'July' {
                        oli.July__c = olis.Quantity;
                    }
                    when 'August' {
                        oli.August__c = olis.Quantity;
                    }
                    when 'September' {
                        oli.September__c = olis.Quantity;
                    }
                    when 'October' {
                        oli.October__c = olis.Quantity;
                    }
                    when 'November' {
                        oli.November__c = olis.Quantity;
                    }
                    when 'December' {
                        oli.December__c = olis.Quantity;
                    }
                    // If it did not find any matches
                    when else {
                        // EDIT: do not put anything here for now
                        // You can leave this empty or put something in here to handle cases where the Month field is NOT the name of the month
                        // e.g. Month field was for some reason populated with 'Apple'
                    }
                }
            }
            OppLineItemList.add(oli);
        }
    }
    update OppLineItemList;
}
Hi guys,

I have created 12 custom number fields in the OppLineItem, each labeled a month of the year. I have also created a custom formula text field in the OppLineItemSchedule object called Month which defines the month based on the scheduled date.
I am trying to create a trigger to map the Quantity value from the related OppLineItemSchedule record to the relevant OppLineItem Month field. I have created the below trigger but the issue is that it is populating every Month field on the OppLineItem with a value even if there is not a related OppLineItemSch Quantity. 

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,Integer> MapMonths = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new) {
         MapMonths.put(sch.OpportunityLineItemId, Integer.valueOf(sch.Quantity));
    }
 
    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c, 
                                            February__c, 
                                            March__c, 
                                            April__c, 
                                            May__c, 
                                            June__c, 
                                            July__c, 
                                            August__c, 
                                            September__c, 
                                            October__c, 
                                            November__c,
                                            December__c From OpportunityLineItem Where Id IN :MapMonths.Keyset()])
    {
        if(MapMonths.containsKey(oli.id))
        {
            OppLineItemList.add(new OpportunityLineItem(Id = oli.id, January__c=MapMonths.get(oli.id), 
                                                                     February__c=MapMonths.get(oli.id),
                                                                        March__c=MapMonths.get(oli.id), 
                                                                     April__c=MapMonths.get(oli.id),
                                                                     May__c=MapMonths.get(oli.id),
                                                                     June__c=MapMonths.get(oli.id),
                                                                     July__c=MapMonths.get(oli.id),
                                                                     August__c=MapMonths.get(oli.id),
                                                                     September__c=MapMonths.get(oli.id),
                                                                     October__c=MapMonths.get(oli.id),
                                                                     November__c=MapMonths.get(oli.id),
                                                                     December__c=MapMonths.get(oli.id)));
                                                                                    
        }
    }
    update OppLineItemList;
}
Hi All,
As of now, Case page layout has Product Pick list, and we can select only one Product and it mainted by Pick List Values.
What I am looking is that, When we create a Case, we should able to select Multiple Products to that Case. How we can achieve this?.

Do we need to create a Junction Object between Cases and Product?.
I think Junction Object is not going to support for Product as Product Standard object is going to be Detail Side of Junction Object, which is not supported by Salesforce.

Please correct me if I am wrong.
Also, please suggest me an alternative methods.

Thanks,
Naren
  • August 14, 2019
  • Like
  • 0
Hi, I have a class which loops through an account and then loops through all of the assets within that account to see if the assets have a certain status. I'm trying to use the contains method on the map of accounts but I'm getting the error message that the method doesn't exist or incorrect signature: void contains(boolean) from the type Map.Is there a way to search the status of the assets within an account to see if the status is present.? Thank you. 
 
public class AccountActiveProducts {

    
    public AccountActiveProducts(){
      List<Account> accountsToUpdate = new List<Account>();
      List<Account> oldAccountsToUpdate = new  List<Account>();
    }
   // public static void updateAccounts(List<SObject> assetLists, Map <Id, Account> AccountOldMap){   
  public static void updateAccounts(List<SObject> assetLists){
            List<Account> accountsToUpdate = new List<Account>();
            Set<String> setAssetsToRemove = new  Set<String>();
            List<String> listAssetsToRemove = new List<String>();
            Set<Id> ParentIds = new Set<Id>();
            for(Asset asset:(List<Asset>)assetLists){
                ParentIds.add(asset.AccountId); 
            }   
        
  //      for(Asset oldAsset:AccountOldMap){
            
  //      }
            Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c,  (Select Id, ProductFamily__c, IsCompetitorProduct, Status from Assets Where  (Status != 'Retired' OR Status != 'Obsolete' OR Status != null)) From Account Where Id In: ParentIds]); 
          //  Map<Id, Account> mapAccountPurchased = new Map<Id, Account>([Select Id,  (Select Id, ProductFamily__c, Status from Assets Where  ( Status != null)) From Account Where Id In: ParentIds]);                                                   


       
            if(Trigger.isInsert || Trigger.isUpdate){ 
               for(Account ac : mapAccount.values()){
  
                   List<String> assetList = new List<String>();
                   Set<String> assetSet = new Set<String>();
                   Set<String> assetsPurchased = new Set<String>();
                   List<String> assetValues =  new List<String>();
                   for(Asset accountAsset: ac.assets){
                   if(accountAsset.Status != 'Retired' || accountAsset.Status != 'Obsolete'|| accountAsset.IsCompetitorProduct != true ){

                       assetSet.add(accountAsset.ProductFamily__c);
                       }
                       
                   
                       
                 //   if(accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete' && (!ac.assets.contains(accountAsset.Status == 'Retired') || !ac.assets.contains(accountAsset.Status == 'Obsolete'))){
                 //    if(ac.assets.contains(accountAsset.status == 'Retired' || accountAsset.status == 'Obsolete' )
                       
              //         if(accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete'|| accountAsset.IsCompetitorProduct == true){
                    
******* This is where I'm trying to search for the status. 

   if((accountAsset.Status == 'Retired' || accountAsset.Status == 'Obsolete'|| accountAsset.IsCompetitorProduct == true) &&  !(mapAccount.contains(accountAsset.Status == 'Installed' || accountAsset.Status == 'Registered' || accountAsset.Status == 'Shipped') )){
                          assetSet.remove(accountAsset.ProductFamily__c);
                       }
                       
                   }
                   assetList.addAll(assetSet);
                   assetList.sort();
                   String productFamily = string.join(assetList,', ' );
                   
                   if(ac.ProductsOwned__c != productFamily ){
                       ac.ProductsOwned__c = productFamily;
                       
                   accountsToUpdate.add(ac);
                   }
                   
               }
            
  
              //End of for loop above
              
          
               
               if(!accountsToUpdate.isEmpty()){
                   upsert accountsToUpdate;
               }
           }
            if(Trigger.isDelete){
                
                
            }
  
            }

}

 
  • August 08, 2019
  • Like
  • 0
Attempting to access the variables MIlestone1_Project__c has a Lookup relationship to Account with relationship name: `Projects__r'.
 
List<Account> accList = [SELECT Id, Name, EHR_Status__c, PM_Status__c,
                                    Project_Imp_Status__c, Other_Status__c,(select Client_Advisor_Email__c,
                                                                                 Resource_Coordinator_Email__c
                                                                                 from Projects__r) 

                             FROM Account
                             WHERE Id IN :AcctIds];
 
List<String> emailAdds = new List<String>();
                 for (Account al: accList) {
                    emailAdds.add(al.Projects__r.Client_Advisor_Email__c);
                    emailAdds.add(al.Projectss__r.Resource_Coordinator_Email__c); 
                 }



Any help is greatly appreciated.
 
Hi guys,

I have a custom object - Object 1 and the Opportunity object. I've created a lookup field from the Opportunity to Object 1 and I am working on a trigger to populate the id of one related record into the lookup field, in order to reference some of the values, back on the Opportunity.

The related records on the Object 1 are being created first (as part of an integration) and one Opportunity, could have 1+ related records, but only one related record will be populated in the lookup field.

Once the lookup field is populated through the trigger, I want to be able to change the picklist value on the Opportunity based on a text field on Object 1. 

I have tried to change the picklist value using PB or Workflow, but it didn't work.

The scenario is to change picklist value to:
  • "A" - if the text field contains "a", but it might also contain "b", "c" or "d", but it should definitely contain "a".
For each picklist is a comibination of the above.

For one picklist value though:
  • "E" - if the text field contain 2 or more of the "a",  "b", "c" "d" combination.
Considering the Opportunity can have more than one related record, I am not sure if it's possibe to do this through a formula - to check all the related records.

Workflow I have tried for one scenarion:

AND (

OR (

ISNEW()
ISCHANGED(Object_1__r.text_field__c)),

CONTAINS(Object_1__r.text_field__c, "a" && ("b" || "c" || "d"))

)

and field update:  picklist value = A

but the fuction ISCHANED cannot be refrenced for my field.

Any help or ideas will be much appreciated.


Thanks.
@isTest
private class TestCtrTurnoverEntryCmp {
    
    @isTest
    static void testTurnoverEntry(){
        
        UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1];
        Profile profile1 = [Select Id from Profile where name = 'System Administrator'];
        User newUser = new User(
            UserRoleId = portalRole.Id,
            ProfileId = profile1.id,
            Username = 'test@managemall.com',
            email = 'test@managemall.com',
            emailencodingkey = 'UTF-8',
            localesidkey = 'en_US',
            languagelocalekey = 'en_US',
            timezonesidkey = 'America/Los_Angeles',
            alias ='nuser',
            lastname ='sahin'
        );
        insert newUser;
        
        system.runAs(newUser) 
        {
            System.debug('Current User: ' + UserInfo.getUserName());
            
            Account acc = new Account(Name = 'portalAccount', OwnerId = newUser.Id);
            insert acc;
            
            Contact con = new Contact (
                AccountId = acc.id,
                LastName = 'portalContact'
            );
            insert con;
            
            User user2 = [SELECT AccountId FROM User WHERE Username =: 
            UserInfo.getUserName()];
            System.debug('user1: ' + user1.AccountId); // this return null

            Test.startTest();
           ......
            Test.stopTest();
        }

    }
}

 
I am trying to write test coverage for a method and receiving the error "Attempt to de-reference a null object" when I run the test.  Below is my test class, can anyone guide me in the right direction with this?

Test class:

static testmethod void getselectOptionsTest(){
        Id RecordTypeIdPropAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Franchisee').getRecordTypeId();
        
        Account fAcct = new Account(Name = 'Test', RecordTypeId=RecordTypeIdPropAccount);
        insert fAcct;
        sObject objObject = [SELECT Id, Name FROM Account WHERE Name = 'Test' LIMIT 1];
        String fld = 'RetailerCategory';
        
        Test.startTest();
        multiPicklistCtrl.getselectOptions(objObject, fld);
        Test.stopTest();
        
    }

Original method:

@AuraEnabled
    public static List <String> getselectOptions(sObject objObject, string fld) {
          system.debug('objObject --->' + objObject);
          system.debug('fld --->' + fld);
          List < String > allCats = new list < String > ();
          // Get the object type of the SObject.
          Schema.sObjectType objType = objObject.getSObjectType();
        
        // Describe the SObject using its object type.
          Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
 
          // Get a map of fields for the SObject
          map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap();

          // Get the list of picklist values for this field.
          list < Schema.PicklistEntry > values =
           fieldMap.get(fld).getDescribe().getPickListValues();

          // Add these values to the selectoption list.
          for (Schema.PicklistEntry a: values) {
           allCats.add(a.getValue());
          }
          system.debug('allCats ---->' + allCats);
          allCats.sort();
          return allCats;    
        }

I'm building a custom Visualforce PDF report that shows all the Opportunity Chatter that happened in the past week. I'd like to have the report broken out something similar to:

  • Account 1
    • Oppty 1
      • Oppty Chatter Post 1a
      • Oppty Chatter Post 1b
    • Oppty 2
      • Oppty Chatter Post 2a
      • Oppty Chatter Post 2b
      • Oppty Chatter Post 2c
  • Account 2
    • Oppty 3
      • Oppty Chatter Post 3a
      • Oppty Chatter post 3b

My current code is able to retrieve the Opportunity Chatter Posts easily enough -- but I'm stumped on figuring out how to modify it so that the chatter posts are grouped by Account, as in the example above.

Here's my current VF page:
 

<apex:page controller="ReportOpptyChatter" renderAs="PDF" showHeader="true" sidebar="false">

    <!-- Summary List of all accounts that had Opportunity Chatter this Week -->
    <table>
        <tr><td>Opportunity Chatter found for the following accounts:</td></tr>
        <tr><td>
            <apex:repeat value="{!Accounts}" var="a" >
                <li><apex:outputText value=" {!a.Name}" /> </li>
            </apex:repeat>
        </td></tr>
    </table>
    <p></p>
    
    <!-- Opportunity Chatter -->
    <table>
       <apex:repeat value="{!ChatterUpdate}" var="update" >
       <tr valign="top"><td><b>Project:</b></td><td><apex:outputField value="{!update.ParentId}" /></td><td align="right"><i>{!update.CreatedBy.Firstname} {!update.CreatedBy.Lastname}</i></td></tr>
       <tr valign="top"><td></td><td colspan="2"><apex:outputText value="{!update.Body}" escape="false" /></td></tr>
       <tr><td></td></tr>
       </apex:repeat>
    </table>
</apex:page>


Here's my current controller:

public class ReportOpptyChatter {

    // List of Opportunity Chatter Posts from Last 7 Days    
    List<OpportunityFeed> opptyChatter= [SELECT Id, Body, ParentId, CreatedDate, CreatedBy.FirstName, CreatedBy.LastName
                                         FROM   OpportunityFeed
                                         WHERE  CreatedDate = LAST_N_DAYS:7
                                         ORDER BY CreatedDate];
    
    // Parent accounts of Oppty Chatter
    public List<Account> getAccounts() {
        Set<Id> opptyIdSet = new Set<Id>();   // Which Opportunities had Chatter this past week?        
        Set<Id> acctIdSet = new Set<Id>();    // Which accounts are those opptys related to?
        
        // Interate through the Oppty Chatter to find a list of unique Opptys
        for (OpportunityFeed i : opptyChatter) {
            opptyIdSet.add(i.ParentId);
        }
        List<Opportunity> opptyList = [SELECT Id, Name, AccountId FROM Opportunity WHERE Id IN :opptyIdSet];
        
        // Itegrate through the Opptys to get a list of unique Accounts
        for (Opportunity o : opptyList) {
            acctIdSet.add(o.AccountId);
        }
        List<Account> accountList = [SELECT Id, Name FROM Account WHERE Id IN :acctIdSet ORDER BY Name];
        
        return accountList;
    }
    
    public List<OpportunityFeed> getChatterUpdate() {
        return opptyChatter;
    }

                               
}

I suspect I probably need a wrapper class, so my VF page and modify the VF page to use nested <apex:repeats> but am unsure how to tackle that.

Hello,

I created a new workflow, but everytime it runs, I get an Apex warning.

The apex warning is :
//
Operation: /aura

By user/organization: 005D0000001VpRg/00D200000000EiN

Caused the following Apex resource warnings:

Number of future calls: 33 out of 50

(these emails can be disabled from the user detail page for this user)
//
 

 

What does it mean? And what can I do to fix this? 

 

The process runs on accounts. 

Hi,

I am having an apex controller with the following method whose return type is again a different class. Below is my code:

@AuraEnabled
public static AccountPagerWrapper getData (Decimal pageNumber ,Integer recordToDisply)
    {
        Integer pageSize = recordToDisply;
        Integer offset = ((Integer)pageNumber - 1) * pageSize;
        
        String queryCount = 'SELECT count() FROM Account';
        
        String finalQuery = 'dynamic query';
        List<Account> returnList = new List<Account>();
        returnList = database.query(finalQuery);       
        
        AccountPagerWrapper obj =  new AccountPagerWrapper();
        obj.pageSize = pageSize;
        obj.page = (Integer) pageNumber;
        
        obj.total =  database.countQuery(queryCount);  
        obj.accounts = returnList;
        return obj;
    }

public class AccountPagerWrapper {
    @AuraEnabled public Integer pageSize {get;set;}
    @AuraEnabled public Integer page {get;set;}
    @AuraEnabled public Integer total {get;set;}
    @AuraEnabled public List<Account> accounts {get;set;}
   }

Can anyone tell how to assign the dynamic query results in accounts property of the AccountPagerWrapper. Line is marked with bold.

I am simply assigning the dynamic query results in the property but it is throwing an error while binding it with the table.

Thnx,
Vai
Hi, 
I have n object student, which has two fields Completed Course(Text) and Course requested(pick List)
User-added image

I have a trigger which update the Completed course field automatically.......
My requirement is to restrict Any user from Editing the Completed Course field manually.
I tried to make this field 'Read Only' , but System Admin Still can edit the record manually.

is there any way such that Completed couse field gets updated only by trigger and nothing else?


Thank you
 
I want to get Event and Tasks from Accounts,Leads using a single query. How Can I do that [By Default if query for Event I will get events from Account and Leads, my convern is to get even and tasks together using single soql]
I am trying to retrieve user IDs which do not belong to those territories whose names starts with IT_CH, but getting error "Unknown error parsing query" in dev console query editor.
Please note I need to use this as a single query and not via executing a class having for loops traversing from Territory to UserTerritory to User:

Select Id from User where Id in (Select UserID from UserTerritory where NOT TerritoryID.name LIKE 'IT_CH%'))

Please help.
  • September 05, 2019
  • Like
  • 0
Hello! I'm trying to write a validation rule where a user can't check a box named "item complete" if the value in a percentage field called "% complete" is not 100%. The error message would tell them to set the % complete to 100% before checking the box. Help is greatly appreciated!

I'd like to let community users login themselves and get user resources in my web app.