• Boss Coffee
  • NEWBIE
  • 490 Points
  • Member since 2019
  • Salesforce Developer

  • Chatter
    Feed
  • 16
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 131
    Replies
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
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.

Hi Team,

I am working on communities, how to get login in the user info.
I am using standard objects such as account, contact, and cases.
In under contact, we have checkbox has superuser. If it is checked login user need to able to view info of all cases associated with the account.
Id accId = [select contactid, contact.accountid from user where id = :userid].contact.accountid;
case ca = [SELECT AccountId,contact.Superuser__c ,CaseNumber,Id,Status FROM Case where status != null and contact.superuser__c = true and accountId =: accid];
Thanks for advance
 

Hey everyone!

I'm trying to wrap my head around this apex class.

We've been trying to figure out what exactly is causing some tasks to auto-complete. I believe its this class, but not entirely sure as I havent worked with the database.batchable method. 

Could someone help me understand what this class does?

 

global class TaskRelatedToAssignerBatch implements Database.Batchable<sObject> {
    
    global Database.Querylocator start (Database.BatchableContext BC) {
		Date today = System.today();
        Date yesterday = today.addDays(-1);
        return Database.getQueryLocator('SELECT Id, WhoId, WhatId, CreatedDate FROM Task WHERE ((Status = \'Completed\' AND Subject LIKE \'Email:%\') OR RecordTypeId = \'0125A000000tbd5\') AND (WhatId = null OR WhatId_String__c LIKE \'001%\') AND WhoId != null AND CreatedDate >= :yesterday');
   }
    
    global void execute (Database.BatchableContext BC, List<sobject> scope) {
        TaskUtils.relateTasksToOpportunityOrAccount(scope);
    }
    
    global void finish(Database.BatchableContext BC) {}

}

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...
 Hi friends
My requirement is place a component in opportunity detail page (get the record details by using  {!v.recordId}) when change and save the Stage(StageName) picklist values in details page  then my component is need to refresh
Here I don’t want to use any button ,link
So I just used  aura:handler    in this action function I used
$A.get('e.force:refreshView').fire();     but is not working 
location.reload();        it is working but problem is entire page will reload number of times i.e it is reload the page continuously it does not stop

    <lightning:input label="current record id" aura:id="recid" value="{!v.recordId}" />
    <aura:handler name="init" value="{!this}" action="{!c.show}" />

({
 
    show : function(component, event, helper)
    {
        var recid=component.find("recid").get("v.value");
        //alert(recid);
        var ledmethod=component.get("c.opprecordidmethod");
        ledmethod.setParams({
            idd:recid,
        }); 
        ledmethod.setCallback(this, function(res){
            if (res.getState() === "SUCCESS")
            {
                var resultval = res.getReturnValue();
                component.set("v.stagename",resultval);
                if(resultval == "Prospecting"){
                    component.set("v.Prospectingcurrent", "resultval");
                    
                }
                if(resultval == "Qualification"){
                    component.set("v.Qualificationcurrent", "resultval");
                    
                    component.set("v.Prospectingcomplete", "resultval");
                }
                 $A.get('e.force:refreshView').fire();     
                //location.reload();
            }
        });
        $A.enqueueAction(ledmethod);  
    }
})

Please help me friends

Thanks in advance

 
Hi all,

I am getting an error 'The Apex class was found' while solving trailhead- Create Test Data for Apex Tests.
Below is my code:
public class RandomContactFactory {
    
    public static List<contact> generateRandomContacts(integer i, string s){
        List<contact> list1= new list <contact>();
        for(integer t=0; t< i; i++){
            
            contact c= new contact();
            c.FirstName=s+' '+t;
            c.LastName=s;
    
        }
        list1=[select FirstName from contact where LastName=:s];
        return list1;              
    }
    
}

need help here !