• Vishal Negandhi
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 15
    Replies
Hello,


I have 2 triggera into sandbox that work s perfectly and I want to transfer it into production. The only problem is that I need to write a test class for each one in order to cover 75% of the triggers in order to fullfill this. My triggers are
 
trigger InsertPriceBookTrigger on Order (before insert) { 
 List<Pricebook2> stdPBL =  [select id from Pricebook2 where IsStandard = TRUE];
 if(!stdPBL.isEmpty()){
  for(Order o: Trigger.new)
   o.PriceBook2Id = stdPBL[0].id;
  }
}
 
​trigger TaskTrigger on Task (after insert) {
    List<Order> ordersToUpdate = new List<Order>();

    for(Task t : Trigger.new) {
        if(t.WhatId.getSObjectType() == Order.sObjectType 
            && t.Subject.startsWith('Email:')) {
                ordersToUpdate.add(new Order(Id = t.WhatId, Status = 'Sent'));
        }
    }

    update ordersToUpdate;
}

Any ideas would be helpfull. Is there any generic way to do this? Any manuals or anything to study through in order to achieve this (and for future purposes as well)
trigger AddAccount on Contact (before insert) 
{
 for (Contact c:Trigger.new )
 {
    Account a= new Account();
    a.Name='ACME';
    a.ID=c.AccountID;
    
    insert a;
 
 }

}


how can i link a Account to a contact ??

Hello,

I followed blog below to display two dependent picklist
https://www.sundoginteractive.com/sunblog/posts/displaying-dependent-picklist-fields-on-a-visualforce-page

public with sharing class locationController{
 
    public list<location__c> locationList{get;set;}
 
    public locationController(){
        locationList = [Select ID, Country__c, State__c, City__c
                From Location__c];
    }
     
}



<apex:page controller="locationController"> 
  Location Table
  <apex:messages style="color:red"></apex:messages>
   
    <apex:form>
        <apex:pageblock>
            <apex:pageblocktable value="{!locationList}" var="locItem">
                <apex:column headervalue="Country">
                    <apex:inputfield value="{!locItem.Country__c}">
                     </apex:inputfield>
               </apex:column>
             
              <apex:column headervalue="State/Province">
                    <apex:inputfield value="{!locItem.State__c}">
                    </apex:inputfield>
               </apex:column>
             
              <apex:column headervalue="City">
                    <apex:inputfield value="{!locItem.City__c}">
                    </apex:inputfield>
               </apex:column>
            </apex:pageblocktable>
        </apex:pageblock>
    </apex:form>
   
</apex:page>
 

How can this example be modified to use "pageBlockSection",  or is there any better way to display picklist and dependent picklist like a pageBlockSection fashion.

 

  • February 17, 2015
  • Like
  • 0
Hi, I have written a test class that keeps failing because of a FIELD_FILTER_VALIDATION_EXCEPTION. I have narrowed it down to the exact problem: Part of a lookup filter (that is looking up a Cash Account) specifies that returned records must have their Status__c = 'Active' (see full lookup filter below). When I remove this part of the filter lookup logic, the test class passes. When I add it back in, the test class fails again.

As you can see in my test class below, I have definitely set the Status__c for the Cash Account record insert to be 'Active'. So I just can't figure out what I'm missing that is causing the test class to fail based on this.

Any help much appreciated.

Lookup Filter:
User-added image

Validation Error:
User-added image

Test Class:
@isTest
 private class TestCashAccountRollUpCashIn {static testMethod void myUnitTest() {Profile pf = [Select Id from Profile where Name = 'System Administrator'];User u = new User();
 u.FirstName = 'Test';
 u.LastName = 'User';
 u.Email = 'testuser@test123456789.com';
 u.CompanyName = 'test.com';
 u.Title = 'Test User';
 u.Username = 'testuser@test123456789.com';
 u.Alias = 'testuser';
 u.CommunityNickname = 'Test User';
 u.TimeZoneSidKey = 'America/Mexico_City';
 u.LocaleSidKey = 'en_US';
 u.EmailEncodingKey = 'ISO-8859-1';
 u.ProfileId = pf.Id;
 u.LanguageLocaleKey = 'en_US';
 insert u;
system.runAs(u){
//Set RecordTypeId variable CA
 String strcaRecordTypeId = [Select Id From RecordType WHERE DeveloperName = 'Person' AND sobjectType = 'Cash_Account__c'].Id;
//Insert a cash account 
 Cash_Account__c ca = new Cash_Account__c();
 ca.RecordTypeId = strcaRecordTypeId;
 ca.Name = 'Test Person';
 ca.Status__c = 'Active';
insert ca;
system.assertEquals(ca.Rollup_Cash_In__c, null);
//Set RecordTypeId variable CT
 String strctRecordTypeId = [Select Id From RecordType WHERE DeveloperName = 'Person_to_Person' AND sobjectType = 'Cash_Transfer__c'].Id;
//Test payments on insert
 Cash_Transfer__c ct1 = new Cash_Transfer__c();
 ct1.RecordTypeId = strctRecordTypeId;
 ct1.Destination__c = ca.Id;
 ct1.Amount__c = 100;
 insert ct1;
Cash_Account__c cau1 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id];
 system.assertEquals(cau1.Rollup_Cash_In__c,ct1.Amount__c);
//Test payments on update
 Cash_Transfer__c ct1u = [select Amount__c from Cash_Transfer__c where Id = :ct1.Id];
 ct1u.Amount__c = 200;
 update ct1u;
Cash_Account__c cau2 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id];
 system.assertEquals(cau2.Rollup_Cash_In__c,ct1u.Amount__c);
//Test payments on second insert
 Cash_Transfer__c ct2 = new Cash_Transfer__c();
 ct2.RecordTypeId = strctRecordTypeId;
 ct2.Destination__c = ca.Id;
 ct2.Amount__c = 800;
 insert ct2;
AggregateResult ag1 = [select sum(Amount__c) from Cash_Transfer__c where Destination__c = :ca.Id];
Cash_Account__c cau3 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id];
 system.assertEquals(cau3.Rollup_Cash_In__c,ag1.get('expr0'));
//Test payment on delete
 delete ct2;
AggregateResult ag2 = [select sum(Amount__c) from Cash_Transfer__c where Destination__c = :ca.Id];
Cash_Account__c cau4 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id];
 system.assertEquals(cau4.Rollup_Cash_In__c,ag2.get('expr0'));
}
}
}

 
  • February 17, 2015
  • Like
  • 0
[select id,name,(select name,AccountId from Contacts) from Account where id in(select AccountId from Contact)]

In this SOQL query,What's the difference between Contacts and Contact.I didn't get this relationship.
Please give a hand.
How can I retrieve a list of installed packages using Apex?
Hi All,

How to add value to the multiselect Picklist through apex code.
I have a requirement to get the value from one Object's text field and  add that values to Multiselect pick list field in another object.


 

I have two standard objects, Order and Contact. I have created a Contact lookup (API- Contact_Lookup__c) in Order and included its related  list in the page layout of Contact.

But when I enter a new record in Contact, then go to related list to add an order to it, hit save, the new Order record gets inserted in the Order records but it does not get displayed in the related list on contact detail page for that record.

Please help

Hi All,

I have an object X__c. it is having a lookup field to itself XC__c. My requirement is , an user can insert only one child record. Simplifying one parent id should be used to one child record. If that parentid is used again or twice trigger should throw an error.

Regards
Hi All,

May i know that Why i am getting following Error while i am updating Record?
But in Debug logs i am getting values that what i want to update. Could you please change my trigger.


Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger editGenerateLogbooks caused an unexpected exception, contact your administrator: editGenerateLogbooks: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: a04f0000005HAXyAAO: Trigger.editGenerateLogbooks: line 68, column 1
 
trigger editGenerateLogbooks on Log_Book__c (after update) {
    
    Set<id> set1 = new Set<id>();
    Set<String> weeks = new Set<String>(); 
    Set<String> subjects = new Set<String>();
    Set<String> students = new Set<String>();   
    List<Weeks__c> weekList = Weeks__c.getAll().values();
    List<Log_Book__c> lb = new List<Log_Book__c>();
    List<Log_Book__c> lbDelList = new List<Log_Book__c>();
    List<Log_Book__c> lstToUpdate = new List<Log_Book__c>();
    Map<Integer,weeks__c> weekMap = new Map<Integer,weeks__c>();
   
    
    for(weeks__c week : weekList)
    {
        weekMap.put((Integer)week.Order__c,week);
         
    }
    for(Log_Book__c lbook : Trigger.old)
    {
        set1.add(lbook.Id);
    }
    lb=[select Abacus__c, Absent_Time_Stamp__c, Absent__c, Attended__c, Class_Scheduled_Date__c, Collected_Book__c, Comments__c, Do_Not_Promote__c, English__c, Level__c, Order__c, Reason__c, Id, Student__c, Subject__c, Subjects_Registered__c, Week__c, Week_Day__c, gk__c, math__c from log_book__c where id in: set1];
    for(Log_Book__c lbdelete : lb)
    {
        if(lbdelete.Class_Scheduled_Date__c >= System.today())
        {
            lbDelList.add(lbdelete);
           
        }
    }
    for(Log_Book__c lbUpdate : Trigger.new)
    {
        
    
            weeks.add(lbUpdate.week__c);
            subjects.add(lbUpdate.Subject__c);
            students.add(lbUpdate.Student__c); 
   
    }
    
      for(Log_Book__c lbup : [select Abacus__c, Absent_Time_Stamp__c, Absent__c, Attended__c, Class_Scheduled_Date__c, Collected_Book__c, Comments__c, Do_Not_Promote__c, English__c, Level__c, Order__c, Reason__c, Id, Student__c, Subject__c, Subjects_Registered__c, Week__c, Week_Day__c, gk__c, math__c from log_book__c where subject__c IN: subjects AND Student__c IN: students AND week__c IN: weeks AND Class_Scheduled_Date__c >=: system.today() order by order__c])
      {
      
          String[] weekLevels = lbup.Week__c.split('-');
          Integer weekLevel = Integer.valueof(weekLevels[0]);
   
       if(lbup.week__c != Trigger.oldMap.get(lbup.id).week__c || lbup.Class_Scheduled_Date__c >= System.Today())
       {
           for(Integer j=weekLevel;j<27;j++)
           {
            system.debug('++hiiiiiiiiiii+');
            lbup.Class_Scheduled_Date__c = lbup.Class_Scheduled_Date__c.addDays(7);
            lbup.week__c = weekMap.get(weekLevel).name;
            system.debug('*****Jagadeesh********'+lbup.Class_Scheduled_Date__c + lbup.Level__c + lbup.Week__c);
            lstToUpdate.add(lbup);
            
            weekLevel++;
            
            }
            weekLevel = 1;
        }
      }
    
   
    
    delete lbDelList;
    update lstToUpdate;
}

User-added image
Hi,

While updating data via data laoder and it will trigger the operation. If the 3rd record enters in custom validation condition, the update fails and the all the records displaying same validation message. Please clear it.

Thanks,
Vetri
Hi Folks
I require code for the following scenario.I have a custom object called Employment history. I need to:
Build a  trigger which identifies the primary account (likely to be the latest active employment record) and adds this value to the parent account field
Ensure this field isn't visible to standard users
Ensure this field is wiped if their employment history is deleted or if all records are set to inactive.

Any ideas?

Many thanks 
  • February 16, 2015
  • Like
  • 0
I need to overwrite the standard edit page for a certain recordType of events. Any ideas how to redirect to the new VF page ?
Hi,
I'm trying to figure how to hide the delete button in the task detail page when the subject field value equal to 'xxxx' and the profile not equal to admin.
I know i need to custom the delete button with a Visualforce Page but i dont have any clue on how the script needs to look like.

Please help me with that,
Thanks in advance,
Matan.
Hi,
It is not a question, I share my experience because I spent hours on this...
on my visualforce page, chrome kept telling me (in the Javascript console):
XMLHttpRequest cannot load https://eu3.salesforce.com/_ui/common/request/servlet/JsLoggingServlet.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://c.eu3.visual.force.com' is therefore not allowed access.
Browsing the net, I didn't find info on this error.
At the end, It appears this was due to a call to the "alert" javascript box just before the call to an "<apex:actionFunction". See below,
Javascript is:
function jsRemoveLineItemCatBtn() {
alert( 'CURRENT ID ' + vLICInProgressNum );
afRemoveLineItemCatBtn( String(vLICInProgressNum) );
}
where afRemoveLineItemCatBtn is the name of my action function.
Since I commented the call to alert, I don't have the error message anymore...
Hope to help few to save time.