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

  • Chatter
    Feed
  • 19
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 144
    Replies
I'm a newbie.
I have a custom object "transaction__c" and looking in the workbench I have many fields, but doens't show the field "response_c"
Image1
 but in the object have him
User-added image

With this I made a query:
SELECT Response__c, name FROM Transaction__c where name ='test';
I execute the query and the return is
User-added image
Thanks.
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.
 

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.
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
  • 1
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
I am trying to add selected products from the list

global class ProductSearchPopupController {
    
    public String query {get; set;}
    public List<PricebookEntry__c> products {get; set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public List<PricebookEntry__c> selectedProduct{get;set;}
    public List<QuoteLineitem__c> quoteLineList{get;set;}
    public List<wrapProduct> selectedWrapperList{get;set;}
    public Boolean normalList{get;set;}
    public Boolean selectedList{get;set;}
    public Boolean block{get;set;}
    public Boolean block1{get;set;}
    public Boolean block2{get;set;}
    public String SalesPrice {get; set;}
    public integer Discount {get; set;}
    public String Quantity {get; set;}
    public String ServiceDate {get; set;}
    Id recordId;
    
    
    public ProductSearchPopupController(ApexPages.StandardController controller){
        recordId = controller.getId();
        SalesPrice='';
        Discount=0;
        Quantity='';
        ServiceDate='';
        system.debug('recordId '+recordId);
        wrapProductList = new List<wrapProduct>();
        selectedWrapperList = new List<wrapProduct>();
        normalList = true;
        selectedList = false;
        block = true;
        block1 = false;
        block2 = false;
    }
    public PageReference runQuery(){
        if(Test.isRunningTest()){
            query='Test';
        }
        system.debug('this query '+query);
        if(query == null || query == ''){
            system.debug('query '+query);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Please enter the product to be searched'));
            return null;
        }
        
        List<List<PricebookEntry__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING PricebookEntry__c (id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c)];
        system.debug('searchResults '+searchResults[0].size());
        System.debug('searchResults  result ' + searchResults[0]);       
        System.debug('oth  result ' + SearchResults[0]);
        if(searchResults[0]!=null){
            for(PricebookEntry__c a: searchResults[0]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapProductList.add(new wrapProduct(a));
                block = true;   block1 = true;   block2 = false;
            }
        }
        return null;
    }
    public void processSelected() {
    wrapProducts = new List<Product2__c>();
 
        for(wrapProducts wrapProductObj : wrapAccountList) {
            if(wrapProductObj.selected == true) {
                selectedProducts.add(wrapProductObj.acc);
            }
        }
    }
 
 
    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
    public class wrapProducts {
        public Product2__c acc {get; set;}
        public Boolean selected {get; set;}
 
        //This is the contructor method. When we create a new wrapAccount object we pass a Account that is set to the acc property. We also set the selected value to false
        public wrapProducts(Product2__c a) {
            acc = a;
            selected = false;
        }
    }
    public PageReference ProceedWithSelectedToNextPage(){
        selectedWrapperList = new List<wrapProduct>();
        normalList = false;
        selectedList = true;
        for(wrapProduct selectedWrapObj: wrapProductList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
                selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
        PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
        pageRef.setRedirect(false);
        return pageRef;
    }
    
 
      
    public void SelectProduct() {
        selectedProduct = new List<PricebookEntry__c>();
        for(wrapProduct wrapProductObj : wrapProductList) {
            if(wrapProductObj.selected == true) {
                selectedProduct.add(wrapProductObj.acc);
                block = false;  block1 = false;  block2 = true;
                
            }
        }
    }
    
    public void GoBack() {
        block = true;
        block1 = true;
        block2 = false;
    }
    
    global   class wrapProduct {
        public PricebookEntry__c acc {get;set;}
        public Boolean selected {get;set;}
        public wrapProduct(PricebookEntry__c p) {
            this.acc = p;
            this.selected = false;
        }
    }
    
    public pagereference saveproduct(){
        List<QuoteLineitem__c> quoteLineList = new  List<QuoteLineitem__c>();
        if(Test.isRunningTest()){
            insertTestData();
        }
        if(!selectedProduct.isEmpty()){
            for(PricebookEntry__c sp:selectedProduct){
                system.debug('sp '+sp);
                QuoteLineitem__c qli = new QuoteLineitem__c();
                qli.QuotesId__c = recordId;
                qli.ListPrice__c = sp.UnitPrice__c;
                qli.UnitPrice__c = sp.UnitPrice__c;
                qli.Product2Id__c = sp.Product2Id__c;    
                if(Discount!=0 || Discount!=null){
                    qli.Discount__c = Discount;
                }
                quoteLineList.add(qli);
            }
            
            if(quoteLineList.size()>0){
                insert quoteLineList;
                PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+recordId+'/view');
                pageRef.setRedirect(true);
                return pageRef;
            }
        }
        return null;
    }
    public void insertTestData(){
        Product2__c testProduct = new Product2__c();
            testProduct.Name='Test product';
            insert testProduct;
            PricebookEntry__c testpbe = new PricebookEntry__c();
                testpbe.Name='Test PriceBookEntry';
                testpbe.UnitPrice__c =123;
                testpbe.Product2Id__c=testProduct.Id;
                insert testpbe;
            selectedProduct.add(testpbe);
    }
}

User-added image
 
OBJECT A - CASE
OBJECT B - CUSTOM 
                3 Record Types ((A or B) and C)

After Case is created, I am trying to write a validation rule that will lock down all editting until two record types are related to the case ((A or B) and C)

I currently have this formula:
AND(
        $RecordType.DeveloperName = "Case_Record_Type",
        A_Rollup__c = 0, 
        B_Rollup__c = 0,
        C__c = 0,
        NOT(ISNEW())
)

I am using "The Power of One" and the "Rollup__c" fields are just number fields. 

This formula does exactly what I want it to do, other than only requires one of the three records to be related and then will unlock the Case record for editting. I need it to stay locked until the records related are (A and C) or (B and C)

 
I have read every possible thread where some have or had the problem that some fields are not being displayed for reports even if the System Admin has Edit permissions on the field or the field is on the layout of the object.

I have built a report with Account as the primary object and following relationships:
User-added image

Account and Object B have a Master-Detail relationship. Object B and C as well. B and C are custom objects.
I would like to add a custom field which is in the object C, say, Name. Name__c is a text field, a custom field.
When building the report type I don't have any chance to add Name__c to the report type. It appears on the right side under C fields as greyed out. No chance to add it. I don't know why.

The field is visible to the Admin, also added on the page layout of the C object. The field is also not blocked via permission set.

But when I build a report type having B and C, the Name__c field appears for selection.

Can someone explain to me what is going on here?
I'm a newbie.
I have a custom object "transaction__c" and looking in the workbench I have many fields, but doens't show the field "response_c"
Image1
 but in the object have him
User-added image

With this I made a query:
SELECT Response__c, name FROM Transaction__c where name ='test';
I execute the query and the return is
User-added image
Thanks.
Hi all,

I've UTC time zone in String type want to insert in SF but facing conversion issue. Can anyone help me out.

Ex. String utcTime='2018-05-03T16:52:23Z'

Want to convert this string into DateTime so i can insert into SF.

TIA
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]