• SFDC 2017
  • NEWBIE
  • 38 Points
  • Member since 2014
  • Salesforce Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 36
    Questions
  • 32
    Replies
Hi All,
I have a requirement where i am displaying child object records in parent record detail page using standard controller and extensions.But the problem is 
in child object there is a picklist field Level with values High and low. I need 2 tables to display in the VF page one table with child Records 
having High as values and the other table with records having Low as value from the child records.Below code which i am sharing is just i am getting 
the record values in pageblock table but i am not sure how to display both the tables which holds different picklist values (High and Low).

Please suggest me how to differentiate the child records based on picklist values from the saved child records and also i have a picklist as Year is it possible to showrecords only for the current year by converting picklist to date ?
Controller:
public with sharing class SampleClass{
    Public Id accId;
    Public List<Contact> con{get;set;}
    
    
    
    
    public SampleClass(ApexPages.StandardController controller) {
        
        
        accId=[SELECT Id,Name FROM Account WHERE id=:ApexPages.CurrentPage().getparameters().get('id')];
        con=[Select Id,Name,Account,Level__c from Account where AccountId= :accId];
        
    }
     
    }
VF page:
<apex:page standardcontroller="Account" extensions="SampleClass">
    
    <apex:Form >
       <apex:pageBlock title="contact details">
        
            
          <apex:pageBlockTable value="{!con}" var="a" style="width:100%"  rendered="{!con.Level__c=='High'}">
                <apex:outputText value="High Level Records"/>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Level__c}"/>
  </apex:pageBlockTable>
       
    </apex:pageBlock>
    </apex:Form>
</apex:page>

Thanks in advance.
Hi All,

I have a problem while updating a parent record lookup field value from child record picklist value in before insert and before update trigger.Below is my code but the problem its not getting updated because its a string value in child object and parent its lookup field.so i am getting String Exception :Invalid Id:

List<Parent__c> ParentLst = new List<Parent__c>();
    Map<String,Id> ParentstateMap = new Map<String,Id>();
    for(ChildObj child : (List<ChildObj>) Trigger.new){
      if(child.Primary__c && String.isNotBlank(child.Country_vod__c) && !ParentstateMap.containsKey(child.Account_vod__c))
              ParentstateMap.put(child.State__c,child.Parent__c);
    }
    
    for(Parent__c pt:[select id,State__c from Parent__c where Id in :ParentstateMap.keySet()]){
            if(ParentstateMap.containsKey(pt.id) && !ParentstateMap.get(pt.id).equals(pt.State__c)){
                pt.State__c = ParentstateMap.get(pt.id);
                ParentLst.add(acct);
            }
        }
    
    if(ParentLst.size() >0){
            try{
                update ParentLst;
            }catch(Exception e){
                System.debug('Exception occurred'+e.getMessage());
            }
    }
Please help me to update lookup field value in parent from child object picklist value

Thanks !!!
Is there any way to read data from excel or fetch data from excel and those records need to delete using apex .I know we can use data loader but for big objects dataloader is not possible so i am in need of doing it by fetching data from excel and delete using apex.

Any suggestion please
Hi All,

I have written a batch apex in a such a way that if string field we are passing then in query it should take other wise no.It is working for single string value but i need to make it work for multiple string values.

Constructor:
global StateBatch(String strfield,Date startDate, Date enddate) {
        
        if(StartDate!= null && Enddate!= null){
            query = 'select Id,Status_vod__c from State__c where Start_Date__c >=:startDate AND End_Date__c<=:endate';
            if(String.isNotBlank(strfield)){
               query += ' AND State__c IN (:strfield)' ;
            }
        }
    } 

Running in DEv console as 
for multiple markets you run it as 
StateBatch sb = new Statebatch ('\'United States of America\',\'United Kingdom\'',Date.newInstance(2019, 02, 13),Date.newInstance(2019, 02, 14)); 
database.executeBatch(sb);
Multiple values it is not taking .How will change to support multiple values.

Thanks in Advance
Hi All,

I have a scenario where i am adding some records to a set <Id> and that Set<Id> we have to add into a List using Addall but that is not possible.I need this list to be passed for Database.delete(List,False).Can i get soem ideas how to pass the set<Id> into a List<Sobject>

Example code:
Set<Id> parSet = new Set<Id>();
List<Account> DelAccLst= new List<Account>();
In this parSet i have some records and then after the forloop we need to add it to the list DelAccLst and this list i have to pass fro Deletion
DelAccLst.addAll(parSet );
Database.delete(DelAccLst,false);

How can i get this done please give me some ideas.

Thanks in advance,
Hi All,
I am not able to cover the Territory related methods which are in my controller .Can anyone please guide me to cover the below methods related to territory in Test class.

public void getTerritories(){
        List<UserTerritory> userTerritories = [select TerritoryId From UserTerritory where isActive=true and userId =:UserInfo.getUserId()];
        List<Territory> territories = new List<Territory>();
        if(!userTerritories.isEmpty()){
            for(UserTerritory userTerritory : userTerritories){
                territories.addAll(getTerritoryHierarchy(userTerritory.TerritoryId));
            }
        }
        territoryOptions = new List<SelectOption>();
        for(Territory territory : territories){
            if(territoryOptions.size()<1000){
                territoryOptions.add(new SelectOption(territory.Id, territory.Name));
            }
        }
    }
public List<Territory> getTerritoryHierarchy(Id highTerrId){
        List<Territory> territories = new List<Territory>();
        Map<Id, Territory> territoriesMap = new Map<Id, Territory>([select Id, ParentTerritoryID, Name from Territory]);
        Territory Terr = territoriesMap.get(highTerrId);
        territories.add(Terr);
        List<Territory> childTerrs = new List<Territory>();
        for(Territory childTerr : territoriesMap.values()){
            if(childTerr.ParentTerritoryId == Terr.Id){
                childTerrs.add(childTerr);
            }
        }
        territories.addAll(childTerrs);
        list<territory> territorylst = new list<territory>();
        territorylst = getTerritoryHierarchy1(childTerrs);
        territories.addAll(territorylst);
        do{
            territorylst = getTerritoryHierarchy1(territorylst);
            territories.addAll(territorylst);
        }while(!territorylst.isEmpty());
public List<Id> getAccFrmTerritories(List<Id> territoryIds){
        List<Group> territoryGroups = [select Id from Group where RelatedId in :territoryIds AND Type='Territory'];
        List<Id> accountIds = new List<Id>();
        if(territoryGroups != null){
            List<Id> territoryGroupIds = new List<Id>();
            for(Group territoryGroup : territorygroups){
                territoryGroupIds.add(territoryGroup.Id);
            }
            List<AccountShare> accountShares = [select AccountId from AccountShare where UserOrGroupId in :territoryGroupIds];
            for(AccountShare accountShare : accountShares){
                accountIds.add(accountShare.AccountId);
            }
        }
        return accountIds;
    }
I am writing a trigger handler for after Insert Scenario.My scenario is I have a Master object called Customer and Child Object as Customer User info Records.When Master Record Customer created with Designation as Data Admin after creation of this master object it needs to check the users which are having Designation(field in child object) as Data Admin has to be pulled and those user info should be stored in Customer User Info child object.(This Object has fields like user profile user license etc.

Thanks in advance
SFDC 2017
Hi All,

I need a help regarding Custom Settings.In Contact we have fields like Firstname,lastname,Email,City etc.So i will store this specified fields in a custom settings (because in future these fields may be change so storing in custom setting )So whenever only this specified field values are updated in contact then only i need to create a record into another object .If other fields are updated it shouldnot trigger.I am not sure how to compare these field changes through Custom Settings and object Contact.

Anyone can give me some idea to get this scenario done.

Thanks in advance
Hi All,
I want to track what are the Email Notifications has been sent from Apex code  .So i want to store whenever an email is send from Custom Object i need to store all the details of that Email like subject ,to Everything into a custom Object..Below is the code:
  Set<String> emailSet = new Set<String>();
                        emailSet.addAll(emailAddress);
                        emailAddress = new List<String>();
                        emailAddress.addAll(emailSet);
                        emailAddressMapWithAccountId.put(acc.Id, emailAddress);
                        
                        Set<String> emailSetBcc = new Set<String>();
                        emailSetBcc.addAll(emailAddressBcc);
                        emailAddressBcc = new List<String>();
                        emailAddressBcc.addAll(emailSetBcc);
                        emailAddressMapWithAccountIdBcc.put(acc.Id, emailAddressBcc);
                        
                        mail = new Messaging.SingleEmailMessage();
                        
                        mail.setToAddresses(emailAddress);
                        mail.setBccAddresses(emailAddressBcc);
                        mail.setTemplateId(templates.get(0).Id);
                        if(contactIDSet.size() > 0){
                            mail.setTargetObjectId(contactIDSet.get(0));
                            mail.setWhatId(CustomobjectID);
                        }else{
                            if(con == null || con.Id == null) {
                                con=[SELECT Id FROM Contact Limit 1]; 
                            }
                            mail.setTargetObjectId(con.id);
                            mail.setTreatTargetObjectAsRecipient(false);  
                            mail.setWhatId(CustomobjectID);
                        }
                        
                        mailArray.add(mail);
After this i m calling one common method to insert the Record of Email into Custom Object called
TrackEmailDetails(What are the Parameters to be passed);
 but i am not sure how to proceed with getting the Template body and To Addresses everything.I want something like below as 
EmailMessage emailMsg = new EmailMessage(); // Created a EmailMessage and copy all details from above.
emailMsg.ToAddress=(emailList[0].getToAddresses())[0];
emailMsg.Subject=emailList[0].getSubject();
emailMsg.HtmlBody=emailList[0].getHtmlBody();
 insert emailMsg;
This is not bulkified .Can anyone please suggest idea how to pass the parameter so i can use this common method anytimes wherever is required

Thanks in Advance

 
Hi All,
I want to track what are the Email Notifications has been sent from my custom Object .So i want to store whenever an email is send from Custom Object i need to store in Activity History .I used SetSaveAsActivity(true) is not working.Below is the code:
  Set<String> emailSet = new Set<String>();
                        emailSet.addAll(emailAddress);
                        emailAddress = new List<String>();
                        emailAddress.addAll(emailSet);
                        emailAddressMapWithAccountId.put(acc.Id, emailAddress);
                        
                        Set<String> emailSetBcc = new Set<String>();
                        emailSetBcc.addAll(emailAddressBcc);
                        emailAddressBcc = new List<String>();
                        emailAddressBcc.addAll(emailSetBcc);
                        emailAddressMapWithAccountIdBcc.put(acc.Id, emailAddressBcc);
                        
                        mail = new Messaging.SingleEmailMessage();
                        
                        mail.setToAddresses(emailAddress);
                        mail.setBccAddresses(emailAddressBcc);
                        mail.setTemplateId(templates.get(0).Id);
                        if(contactIDSet.size() > 0){
                            mail.setTargetObjectId(contactIDSet.get(0));
                            mail.setWhatId(CustomobjectID);
                        }else{
                            if(con == null || con.Id == null) {
                                con=[SELECT Id FROM Contact Limit 1]; 
                            }
                            mail.setTargetObjectId(con.id);
                            mail.setSaveAsActivity(true);
                            mail.setTreatTargetObjectAsRecipient(false);  
                            mail.setWhatId(CustomobjectID);
                        }
                        
                        mailArray.add(mail);

I am not sure why SetSaveAsActivity is not working.I want to track all email under my custom object

Thanks in Advance
                    }
                }
            }
Hi All,
I have a test class which is having some assertion statement .When we are deploying to QA it successfully passed but when validating the same with PROD the assertion Statement is failing.
Code where assertion is failing
 private static testMethod void LeadUtil() {
        createTestData();
        insert testLead;
        Test.startTest();
            Database.executeBatch(new testbatch(), 200);
        Test.stopTest();
        Lead Lead = [SELECT Id, OwnerId FROM Lead WHERE ID =: testLead.Id LIMIT 1];
        //system.assertEquals(Lead.OwnerId, standardUser.Id);
    }system.runAs(new User(Id=UserInfo.getUserId())) {
            standardUser = Test.createUser('12', STANDARDUSER, false);
            standardUser.IsActive = true;
            standardUser.Phone = '123871287';
            insert standardUser;
        } 
        
        system.runAs(new User(Id = UserInfo.getUserId())) {
            territory1 = Test.createTerritory('Test_Territory1', models.get(0).Id,CHILD, true);
            ota = Test.createOTA(acc.Id, territory1.Id, true);
            uta = Test.createUTA(standardUser.Id, territory1.id, Territoryrole);
        }
        //test lead creation
        testLead = Test.createLead('Test LEad', false);
        testLead.Account__c = acc.Id;
        testLead.Contact__c = con.id;
       
How to reslove this?Batch will not complete execution in test class or not ?WHy thi sassertion is failing in PROD.
Thanks in advance
    
 
Hi All,

We have ae afterinsertupdate trigger and we are calling handler class for that .Since we want the Id field of the lead so we used after insert and after update but now test class is failing with the below error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadTrigger: execution of AfterInsert

caused by: System.FinalException: Record is read-only.
Stack TraceClass:LeadAssignmentUtilTest.testLeadAssignment1: line 39, column 1
 private static testMethod void testLeadAssignment1() {
        createTestData();
        Test.startTest();
            insert testLead;
            Lead updatedLead = [SELECT Id, OwnerId FROM Lead WHERE ID =: testLead.Id LIMIT 1];
            system.assertEquals(updatedLead.OwnerId, standardUser.Id);
        Test.stopTest();
    }
I can,t change this to before insert because we need id of the Lead.some one please help me this is little urgent.

Thanks in advance,
 
Help on REGEX
In Visualforce Javascript Function we have a email Regex as Below:
var emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; This is helpful for email format.But now the Problem is if users enter spaces or any character at first iit should not allow.Means first 2 characters should be either a-zA-Z0-9.I created a seperate Regex as var textRegex = /^[a-zA-Z0-9]{2}/; It is working for other Text fields but for this email field it is not throwing error ,Please some one explain how to achieve this

Thanks in advance
Hi I am running a batch job in that i am getting Too many DML rows: 10001 error .Eventhough i am spliting the batch every 10000 Records but still i am getting that error.i tried all possible ways still i am getting same error.

List<Candidate__c> Candidatelist = new List<Candidate__c>();
List<Database.Saveresult> saveList = new List<Database.Saveresult>();
 if(Candidatelist!=null && Candidatelist.size()>0){
            integer i=0;
            List<Candidate__c> Candidatelistk = new List<Candidate__c>();
            for(Candidate__c ctc: Candidatelist){
                i=i+1;
                Candidatelistk.add(ctc);
                if(i>=9999){
                    saveList.addAll(Database.insert(Candidatelistk, false));//error in this line
                    i=0;
                   Candidatelistk.clear();
                }
            }
            saveList.addAll(Database.insert(CandidatelistK, false));

Thanks in advance
      
Hi All,
I have a List custom setting in which source and Target field is there.So 2 mappings data in Custom Setting like one with source as contact Id an danother with accountId.I need to skip the records creation if the Source field where Account and contact is Null then no need to create.So i want to check if the CS is not null || this sourcefield.Account && sourcefield.contact is not blank then create records .How to check this condition in Apex code?
Hi All,

I have written a batch class with the below scenario.
if (ObjectName==Account)
{ need to query account  records
}
else if (ObjectName =Contact )
{ Query Contact records)
}
So i will get either account or contact records in scope and in execute method i will create records for other custom object means if it is account it will insert with account Id in the new custom object and if Contact contact Id in the new object .Right now it is captuirng the Id into another custom Object but the problem is whenever i am executing it is capturing the same .

So here i want to eliminate the creation of duplicates means if the Record Id(Acc or con Id already in the new custom object then it should not create new record if the record is not existing then create new record with the Acc or Con Id

My Code:
  global void execute(Database.BatchableContext BC, List<SObject> scope)
    { 
        Map<id, Custom Object> CustomMap= new Map<id,Custom Map>();
         for(Sobject obj: scope)
         {      
                Custom Object cm= new Custom Object();
                 
                 cm.Recordt_ID__c =obj.Id;
                 
                  CustomMap.put(Cm.Object_ID__c, cm);
             
          }
          if(!CustomMap.isEmpty())
        {
            Database.SaveResult[] InsertResult = Database.insert(CustomMap.values(),false);
            
        }
        
    }

So here how i will check if there is already a record with same Object Id is there then it should not insert if it is not there it should create new custom object Record.Any one please guide how to do this

Thanks in advance
Hi All,  I used batch Apex normally but using dynamic apex i am new.Can anyone please guide me for the Following Scenario using Batch Apex(Dynamic)
 In Batch Class constructor: global Account batch(String ObjectName)  
My scenario i passed this ObjectName as parameter and
if (ObjectName==Account)
{ need to query account  records
}
else if (ObjectName =Contact )
{ Query Contact records)
}
So i will get either account or contact records in scope and in execute method i will create records for other custom object based on this scope And in scheduler class how i will pass for account and contact  
Please anyone guide me to do this  
Thanks in advance
Hi All,

I am working on one scenario where there are Multiple Child Records for eg:Account is a parent and Under Account multiple child Objects Records will be there.In that child Object i have created one checkbox field called Primary and first record should be primary and if users adding another record as primary it has to thrwo error Message there is already one primary Record please unselect the existing record and add new record as primary marked
Eg:Let say under account 3 child records are there and 1 is primary already and user is trying to add the 3 rd record as primary it should throw error Message
NEXT There are 3 Multiple Child Records and one is primary among them and user is trying to delete the primary record without marking any other records as primary then it should throw error Message as User is trying to Delete primary Record without making another primary
If there is only one primary and user is trying to delete then it should allow the user to delete.
Note :Child Record Refers to Contact 
Any one please guide me to help to implement this scenarios.
Hi All,
I am stuck with the Case Assignment Rules.We have around 19 Assignment rules from 1 to 19.When creating the case it is assigning properly to the correct Team second time if i update also it will be assigne dto same user since i have one rule with update also it wil be in the same team since i have checked donot reassign user checkbox.But if i am updating the Same record for the Second time it is assigning to Admin User .How is that possible ?
I am not able to find in Debug Logs also.How to Resolve this or is there any other ideas for this 

If some one knows about this issue please guide me to resolve this issue.
I have a scenario account and custom object Zip .So if the account Billing postal code is same as zip object zip field then in Accountt Zip lookup field will get updated .For Billing code like 75020-5678 it has to take the first 5 andcompare with zip object with that 5 characters.My code is as below .The Lookup field is not updating 
 Set<String> zipCodes = new Set<String>();
    Set<String> countryCodes = new Set<String>();
    Set<String> accountSegments = new Set<String>();
    List<String> zipCodes_Sorted = new List<String>();
    String zipStartMin, zipStartMax;
    List<Account> lstAccountsToUpdateZipTerritoryName = new List<Account>();
    System.Debug('%%%%%%LIST OF ACCOUNTS'+lstAccountsToUpdateZipTerritoryName);
    System.Debug('&&&&&&mapOldAccounts '+mapOldAccounts);
    if(mapOldAccounts != null && mapOldAccounts.size() > 0) {
      for(Account accRec : newAccounts) {
        if(String.IsNotBlank(accRec.BillingPostalCode) && String.IsNotBlank(accRec.BillingCountryCode) && String.IsNotBlank(accRec.Account_Segment__c)
          && (
           !accRec.BillingPostalCode.equalsIgnoreCase(mapOldAccounts.get(accRec.Id).BillingPostalCode) ||
           !accRec.BillingCountryCode.equalsIgnoreCase(mapOldAccounts.get(accRec.Id).BillingCountryCode) ||
           !accRec.Account_Segment__c.equalsIgnoreCase(mapOldAccounts.get(accRec.Id).Account_Segment__c)
          )) {
          lstAccountsToUpdateZipTerritoryName.add(accRec);
          System.Debug('@@@@@@@@Account List'+lstAccountsToUpdateZipTerritoryName);
          System.debug('LIST ACCOUNT SIZE'+lstAccountsToUpdateZipTerritoryName.size());
          System.Debug('*******%%%%Account RECORD'+accRec);
          if(accRec.BillingCountryCode=='US')
          {
            String s=accRec.BillingPostalCode;
            System.Debug('&&&&&BILLINGPOSTAL CODE'+s);
            String s2=s.mid(0,5);
            zipCodes.add(s2);
            zipCodes.add(s2);
            System.Debug('*****%%%%%%%%'+s2);
            System.Debug('@@@@ZIPCODES'+zipCodes);
          }
          else 
          {
              zipCodes.add(accRec.BillingPostalCode);
           }

          countryCodes.add(accRec.BillingCountryCode);
          accountSegments.add(accRec.Account_Segment__c);
        } else if(String.isNotBlank(mapOldAccounts.get(accRec.Id).BillingPostalCode) && String.IsBlank(accRec.BillingPostalCode)) {
          accRec.ZipAssignments__c = null;
        }
      }

      zipCodes_Sorted.addAll(zipCodes);
      zipCodes_Sorted.sort();
      System.Debug('%%%%%%%%%%%%SORTED ZIPCODES'+zipCodes_Sorted);
      System.Debug('$$$$$$Sorted ZipCodes Size'+zipCodes_Sorted.size());
      // Bulk Support
      if(lstAccountsToUpdateZipTerritoryName.size() >= 1 && zipCodes_Sorted.size() > 0) {//It is entering to this loop but after 
        zipStartMin = zipCodes_Sorted[0];
        zipStartMax = zipCodes_Sorted[zipCodes_Sorted.size() -1];
        System.Debug('&&&&&&&ZIPSTARTMIN'+zipStartMin);
        System.Debug('!!!!!!!ZIPSTARTMIN'+zipStartMax);
        List<ZipAssignments__c> sortedZipAssignments_IN = [ SELECT  Id, Zipcode_Start__c, Zipcode_End__c,
                                                                    Account_Segment__c, Country_Code__c
                                                            FROM    ZipAssignments__c
                                                            WHERE   Action__c = :IS_Constants.CONST_INSERT
                                                            AND     Zipcode_Start__c <= :zipStartMin
                                                            AND     Zipcode_End__c >= :zipStartMax
                                                            AND     Country_Code__c IN :countryCodes
                                                            ORDER BY Zipcode_Start__c];
             System.debug('^^^^^^^^SORTEDZIPASSIGNMENTS'+sortedZipAssignments_IN );//till here it is executing
        for(Account objAccount : lstAccountsToUpdateZipTerritoryName) {
          objAccount.ZipAssignments__c = null;
          for(ZipAssignments__c objZip : sortedZipAssignments_IN) {
            if(objZip.Country_Code__c.equalsIgnoreCase(objAccount.BillingCountryCode) &&
               objZip.Account_Segment__c.equalsIgnoreCase(objAccount.Account_Segment__c) &&
               objZip.Zipcode_Start__c <= objAccount.BillingPostalCode && objZip.Zipcode_End__c >= objAccount.BillingPostalCode ) {
              objAccount.ZipAssignments__c = objZip.Id;
               System.Debug('ACCOUNT ZIP'+objZip.Id);
              break;
            }
          }
        }
      }

Any one look into it and kindly provide what is the mistake i am doing
Hi All,

I need a help regarding Custom Settings.In Contact we have fields like Firstname,lastname,Email,City etc.So i will store this specified fields in a custom settings (because in future these fields may be change so storing in custom setting )So whenever only this specified field values are updated in contact then only i need to create a record into another object .If other fields are updated it shouldnot trigger.I am not sure how to compare these field changes through Custom Settings and object Contact.

Anyone can give me some idea to get this scenario done.

Thanks in advance
Is there any way to read data from excel or fetch data from excel and those records need to delete using apex .I know we can use data loader but for big objects dataloader is not possible so i am in need of doing it by fetching data from excel and delete using apex.

Any suggestion please
Hi All,

I have written a batch apex in a such a way that if string field we are passing then in query it should take other wise no.It is working for single string value but i need to make it work for multiple string values.

Constructor:
global StateBatch(String strfield,Date startDate, Date enddate) {
        
        if(StartDate!= null && Enddate!= null){
            query = 'select Id,Status_vod__c from State__c where Start_Date__c >=:startDate AND End_Date__c<=:endate';
            if(String.isNotBlank(strfield)){
               query += ' AND State__c IN (:strfield)' ;
            }
        }
    } 

Running in DEv console as 
for multiple markets you run it as 
StateBatch sb = new Statebatch ('\'United States of America\',\'United Kingdom\'',Date.newInstance(2019, 02, 13),Date.newInstance(2019, 02, 14)); 
database.executeBatch(sb);
Multiple values it is not taking .How will change to support multiple values.

Thanks in Advance
Hi All,

I need a help regarding Custom Settings.In Contact we have fields like Firstname,lastname,Email,City etc.So i will store this specified fields in a custom settings (because in future these fields may be change so storing in custom setting )So whenever only this specified field values are updated in contact then only i need to create a record into another object .If other fields are updated it shouldnot trigger.I am not sure how to compare these field changes through Custom Settings and object Contact.

Anyone can give me some idea to get this scenario done.

Thanks in advance
Hi All,

We have ae afterinsertupdate trigger and we are calling handler class for that .Since we want the Id field of the lead so we used after insert and after update but now test class is failing with the below error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadTrigger: execution of AfterInsert

caused by: System.FinalException: Record is read-only.
Stack TraceClass:LeadAssignmentUtilTest.testLeadAssignment1: line 39, column 1
 private static testMethod void testLeadAssignment1() {
        createTestData();
        Test.startTest();
            insert testLead;
            Lead updatedLead = [SELECT Id, OwnerId FROM Lead WHERE ID =: testLead.Id LIMIT 1];
            system.assertEquals(updatedLead.OwnerId, standardUser.Id);
        Test.stopTest();
    }
I can,t change this to before insert because we need id of the Lead.some one please help me this is little urgent.

Thanks in advance,
 
Hi All,

I have written a batch class with the below scenario.
if (ObjectName==Account)
{ need to query account  records
}
else if (ObjectName =Contact )
{ Query Contact records)
}
So i will get either account or contact records in scope and in execute method i will create records for other custom object means if it is account it will insert with account Id in the new custom object and if Contact contact Id in the new object .Right now it is captuirng the Id into another custom Object but the problem is whenever i am executing it is capturing the same .

So here i want to eliminate the creation of duplicates means if the Record Id(Acc or con Id already in the new custom object then it should not create new record if the record is not existing then create new record with the Acc or Con Id

My Code:
  global void execute(Database.BatchableContext BC, List<SObject> scope)
    { 
        Map<id, Custom Object> CustomMap= new Map<id,Custom Map>();
         for(Sobject obj: scope)
         {      
                Custom Object cm= new Custom Object();
                 
                 cm.Recordt_ID__c =obj.Id;
                 
                  CustomMap.put(Cm.Object_ID__c, cm);
             
          }
          if(!CustomMap.isEmpty())
        {
            Database.SaveResult[] InsertResult = Database.insert(CustomMap.values(),false);
            
        }
        
    }

So here how i will check if there is already a record with same Object Id is there then it should not insert if it is not there it should create new custom object Record.Any one please guide how to do this

Thanks in advance
Hi All,  I used batch Apex normally but using dynamic apex i am new.Can anyone please guide me for the Following Scenario using Batch Apex(Dynamic)
 In Batch Class constructor: global Account batch(String ObjectName)  
My scenario i passed this ObjectName as parameter and
if (ObjectName==Account)
{ need to query account  records
}
else if (ObjectName =Contact )
{ Query Contact records)
}
So i will get either account or contact records in scope and in execute method i will create records for other custom object based on this scope And in scheduler class how i will pass for account and contact  
Please anyone guide me to do this  
Thanks in advance
Hi All,

I am working on one scenario where there are Multiple Child Records for eg:Account is a parent and Under Account multiple child Objects Records will be there.In that child Object i have created one checkbox field called Primary and first record should be primary and if users adding another record as primary it has to thrwo error Message there is already one primary Record please unselect the existing record and add new record as primary marked
Eg:Let say under account 3 child records are there and 1 is primary already and user is trying to add the 3 rd record as primary it should throw error Message
NEXT There are 3 Multiple Child Records and one is primary among them and user is trying to delete the primary record without marking any other records as primary then it should throw error Message as User is trying to Delete primary Record without making another primary
If there is only one primary and user is trying to delete then it should allow the user to delete.
Note :Child Record Refers to Contact 
Any one please guide me to help to implement this scenarios.
Hi All,
    I have two Custom Objects A and B with Master Detail Relationship.We have written one trigger with Before Insert and Before update Trigger for auto populating A field in B Object based on Five conditions .Trigger is working fine.But when we Upload Bulk records of Achievements through Data Loader nearly 40 k Records some are updating the Target Field and some of them are not updating.Some records won't match the conditions thats is fine but some records of Achievements if i update manually it is populating.We checked by reducing the Batch Size also still not resolved.Can any one help on this issue as soon as possible.I am posting the code as well can anyone help me on this trigger to make work for bulk Records also...

trigger populateAfield on ObjectB(before insert,before Update) 
{
   set<id> userids =new set<id>();
   set<id> accids =new set<id>();
   set<string> plant=new set<string>();
   set<string>rgn=new set<string>();
   set<string> compont=new set<string>();
   set<integer> Month =new set<integer>();
   set<Decimal> invceamt = new set<Decimal>();
   
   Map<id,ObjectA> mpA = new map<id,ObjectA>();
   
     forObjectB ac :trigger.new)
     {
         /*if(ac.User__c!=Null)
         {
            userids.add(ac.User__c); 
         }*/
         if(ac.Account__c!=null)
         {
             accids.add(ac.Account__c);
         }
         if(ac.Plant__c!=null)
         {
             plant.add(ac.Plant__c); 
         }
         
         if(ac.Component__c!=Null)
         {
             compont.add(ac.Component__c);
         }
         
         if(ac.Invoice_Date__c!=null)
         {
           month.add(ac.Invoice_Date__c.Month());
         }
         if(ac.Region__c!=null)
         {
            rgn.add(ac.Region__c); 
         }
        
     }
     
  List<ObjectA>A = [select id,OwnerId,Name,Account__c,Component__c,Plant__c,Region__c,
        Target_Amount__c,Target_Date__c,User_Name__c from A Where Region__c IN:rgn  AND CALENDAR_MONTH(Invoice_Date__c) IN :month AND 
                   Account__c IN:accids AND Component__c IN:compont AND Plant__c
                   IN :plant   
                  //AND User_Name__c IN :userids
                   ]; 
                       
         if(A!=null)
         {
              for(ObjectA  t:A )
              {
                   mpA .put(t.Account__c,t); 
                   system.Debug('@@@@@@@@@@@@@@@@@@@@@@@'+mpA);
              } 
         } 
         
        if((mpA .Size()>0))
           { 
        for(ObjectB ach:Trigger.New)
          {
          if(ach.Account__c!=Null)
          {
              if(mpA .get(ach.Account__c)!=Null)
              {
         Integer acmonth=ach.Invoice_Date__c.Month();
          Integer tarmonth=mpA .get(ach.Account__c).Invoice_Date__c.Month();
               if((ach.Account__c==mpA .get(ach.Account__c).Account__c)&&(ach.Component__c==mpA .get(ach.Account__c).Component__c)&&
                  (ach.Region__c==mpA .get(ach.Account__c).Region__c)&&(acmonth==tarmonth)&&
                  (ach.Plant__c==mpA .get(ach.Account__c).Plant__c))                       
                  {
                                  
                   ach.Target__c = mpA .get(ach.Account__c).id;  
                                        
                  }
               }
           }
       } 
       }  
      
                                                                
}



Thanks in advance...!!!
Hello,

I'm trying to complete the "Using Formula Fields" section in trailhead.
The task is:

For easier reporting and filtering, create a new custom formula field on the standard account object which looks at the SLA Expiration Date field and returns true if the current date comes after it. Otherwise, it should return false.The account object should have a custom date field with the Field Label 'SLA Expiration Date' and Field Name of 'SLAExpirationDate'. The resulting API Name should be 'SLAExpirationDate__c'. On a Developer Edition, the 'SLA Expiration Date' field may already exist.
The new formula field should have the Field Label 'SLA Expired' and Field Name of 'SLA_Expired'. The resulting API Name should be 'SLA_Expired__c'.
The formula field should be of type 'Checkbox'.
The formula field should calculate its response based on the current date.
The formula field should return true if the SLA has expired, and false if it has not.


My syntax is: SLA_Expiration_Date__c < Today()

The error message I am receiving is: 
Challenge not yet complete... here's what's wrong: 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: LUVRAIPP


Any help is appreciated.
 
Hai All,
I am facing a Problem while deploying Trigger into Production.I am Facing the below error while deploying:

Error Message
testAccountHierarchy testAccountHierarchy System.Exception: Apex CPU time limit exceeded
Stack Trace: Class.InlineAcountHerachy_TestUtilities.checkObjectCrud: line 39, column 1 Class.InlineAcountHerachy_TestUtilities.updateAccountList: line 101, column 1 Class.AccountHierarchyTestData.createTestHierarchy: line 33, column 1 Class.testAccountHierarchy.testAccountHierarchy: line 6, column 1.

This is because of a Class .InlineAcountHerachy_TestUtilities that we installed from Appexchange developed by Force.com Labs.
This is the name of the app Inline Account Hierarchy, please find the link
https://appexchange.salesforce.com/listingDetail?listingId=a0N300000016chCEAQ.

Please anyone help me on this issue and tell me how to resolve this quickly because this is little bit urgent .Because of this i am  not able to share Accounts .

I am attaching the scrrenshot of the Error Message for reference.

User-added image
Hi All,
  My scenario is I want custom Dupecatcher functionality for Contact Object using Trigger.For that condition Account is having two types of Recordtypes.Company and Person .So i created a formula field in Contact for getting that Account Recordtype in contact level.so based on that formula field i created in contact it should check duplicates.Because the  email and mobile which they are  having in Person will be replicted in Company contacts also but it will not replicate in Person contatc types.Which means email and mobile in Person Contacts will also be in Company contacts but willnot be again in Person Contacts.


Can any one suggest me for writing trigger for this Scenario.



Hi All

I have a custom object for RFPs.  What I need is when sales submits the RFP for pricing I need the owner of that record to round robine evenly between 3 people.

Step 1 - The sales rep fills out the RFP information and then changes the status to Submitted. 
Step 2 - I now want this to round robin evenly between 3 other employees

Its a pretty simple I think it can be done with a few workflows and field updates just not sure how

thank you in advance for your help
  • May 19, 2014
  • Like
  • 1

Hi everyone,

 

    I am a newbie to FDC (so please correct me if I am wrong anywhere) . I have gone thorugh Apex REST API and found that we can create our custom web services in Apex and expose them as REST services using Apex REST. But in most of the references it is given that we can use any programming language of our choice ( i.e. from outside FDC) to invoke this custom WS via REST API. But I want to invoke the same using Apex code (i.e., from inside FDC) via REST API.

 

Any help is highly appreciated

  • August 25, 2011
  • Like
  • 0