• Puneetsfdc
  • NEWBIE
  • 130 Points
  • Member since 2015

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 21
    Replies
Hi expert,

I have trigger below and it got soql exception. I just join project few days so I do not understand the logic of the flow. Can any one advise to improve the code. I see SOQL in for loop:
     if (Trigger.isInsert) {
                
                LineItemFormController.isInsertTrigger = true;
                for(Line_Item__c item :Trigger.New){
                if ((lineItemRecordType != '') && (item.Cloned_Line_Item__c == null) && (item.RecordTypeId == lineItemRecordType)) {
                    lineItemIds.add(item.Id);
                    if (lineItemMaps.get(item.Id) == null) {
                        lineItemMaps.put(item.Id, new List<Line_Item__c>());
                    }
                    }
                }
                
                List<Line_Item__c> oldAuditLineItems = [SELECT Id,Line_Item__c, Active__c, Line_Item_Status__c
                                                    FROM Line_Item__c
                                                    WHERE RecordTypeId =:auditRecordType
                                                    AND Active__c = true
                                                    //US5105
                                                    AND Line_Item_Status__c != 'Audited'
                                                    AND Line_Item__c IN :lineItemIds
                                                   ];
                for (Line_Item__c auditItem : oldAuditLineItems) {
                    lineItemMaps.get(auditItem.Line_Item__c).add(auditItem);
                }
                System.Debug('nghiatran: Insert ' + isUpdate);
                System.Debug('vinhvinh: Come to Insert Audit trigger');
                for(Line_Item__c item :Trigger.New){
                    Line_Item_Type__c lineItemType  = [SELECT Id,Line_Item_Category_Text__c,Line_Item_Type_Aggregated_Category__c,Name FROM Line_Item_Type__c where id =: item.Line_Item_Type__c limit 1];
                    if ((item.Cloned_Line_Item__c == null) && (item.RecordTypeId == lineItemRecordType)) {
                        // US6137 insert start
                        system.debug('nghiatran lineItemType.Line_Item_Type_Aggregated_Category__c ' + lineItemType.Line_Item_Type_Aggregated_Category__c);
                        if(lineItemType.Line_Item_Type_Aggregated_Category__c == 'Electoral Expenditure' ||
                            lineItemType.Line_Item_Type_Aggregated_Category__c == 'Small Donations Made' ||
                            lineItemType.Line_Item_Type_Aggregated_Category__c == 'Small Donations Received')
                            return;
                        // US6137 insert end
                       if (lineItemMaps.get(item.Id).size() == 0 ) {
                           system.debug('nghiatran access insert after ' + lineItemType.Line_Item_Type_Aggregated_Category__c);
                            Line_Item__c temp = item.Clone(false,true);
                            temp.Line_Item__c = item.Id;
                            temp.Line_Item_Type__c = item.Line_Item_Type__c;
                            temp.RecordTypeId = auditRecordType;
                            temp.Active__c = true;
                            temp.Line_Item_Status__c = 'Not Audited';
                            newAuditLineItems.add(temp);
                        }
                    }
                }
            }
I am trying to print Account Name and related cotact name in the other columns of pageblocktable

<apex:page standardController="Account" extensions="CustAccContExtn" >
    <apex:form >
        <apex:pageBlock title="A/c and Cont in Table" >
            <apex:pageblockButtons location="bottom">
                <apex:commandButton value="Fetch Account" action="{!getAccountsResc}"/>
            </apex:pageblockButtons>
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!allAccs}" var="ac">
                    <apex:column value="{!ac.Name}" headerValue="Account Name"/>
                    
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

public class CustAccContExtn {
    
    public List<Account> allAccs {get;set;}
    
    public PageReference getAccountsResc() {
        allAccs = [SELECT id, Name FROM Account];
        return null;
    }
    public CustAccContExtn(ApexPages.StandardController controller) {
        allAccs =  new List<Account>();
    }
}


What update do I need to make on select statement to pull the name of all contact associated for an account and how do i call them in apex:column

Please Help!

 
  • March 29, 2015
  • Like
  • 0
Is it possible to pull through a merge field to the HPYERLINK formula in a Formula (Text) field?

The link works in as a custom link/button eg. www.website.com/form?pa0={Contact.Email} - however this same link does not pull through the field, but treats the field merge it as text when used in a Formal (Text) fields as: HPYERLINK (www.website.com/form?pa0={Contact.Email}).

Any help ont his would be much appreciated.
Hi, 

Please halp me with a problem I am having. Here is what I want to happen: from the Task which is assigned to me I click a button and I get to an Opp create wizard and some of the fields are pre-populatd using values form that Task. I am having some success, but am stuck at one point. 

First of all my Task has 4 custom fields wich I want to grab and use their values to pre-populate fileds on an Opp. User-added image

Now, I created a new button and placed it on the Task layout. The button is Detail Page Button and I am trying to use "URL Hack" to pre populate some of the fields. Here is the code for my button 
/006/e?
ent=Opportunity
&nooverride=1
&RecordType=012U0000000ZW7x
&00NU0000003aXaU=New
&opp4={!Account.Name}
&CF00NU0000003aZwA ={!Contract.Id}
&00NK0000001jB5V = {!Task.Type}      // custom field 
&00NK0000001jB5G = {!Task.Marketing_Activity_Name__c}   // custom field 
&00NK0000001jB5L = {!Task.Last_Referrer__c}   // custom field 
&00NK0000001jB5Q = {!Task.Offer_ID__c}   // custom field 
&retURL=%2F006%2Fo

As you can see I have 4 new fields on an Opportunity Object to accomodate the mapping, I grab their IDs and try to force task field values on them. 

Now the stange part. When I click on the "Create Opportunity" button it does take me to the Opp create wizard and my fields are blank, BUT the Opp wizard URL shows that values are there.

User-added image

Here is the full URL I get once on the Opp create wizard page:
https://cs9.salesforce.com/006/e?ent=Opportunity&nooverride=1&RecordType=012U0000000ZW7x&00NU0000003aXaU=New&opp4=Test+Account+05&00NK0000001jB5V%20=%20Outbound+Prospecting&00NK0000001jB5G%20=%20Marketo+Push+2&00NK0000001jB5L%20=%20www.wsj.com&00NK0000001jB5Q%20=%209876543210&retURL=%2F006%2Fo

Any ideas what might be causing this behaviour? I am completely lost. My "URL Hack" works for some othe fields, but not for these. 

Any input will be appreciated.
Hi Guys,
Can you please help me out with this formula field.
IF Submission_Date__c <> NULL AND Record Type Name = "Account Number Issue" then show me Estimated_Completion_Date3__c
IF Submission_Date__c <> NULL AND Record Type Name = "New Order Assistance/Special" Terms then show me Estimated_Completion_Date3__c
IF Record Type is other than these 2 then and Submission_Date__c <> NULL it should show Estimated_Completion_Date1__c

I am trying this code below but it is not giving me the right Date. It is showing Estimated_Completion_Date1__c in all the Record Types

IF(AND(Submission_Date__c <> NULL, RecordType.Name = "Account Number Issue"), Estimated_Completion_Date3__c
IF(AND(Submission_Date__c <> NULL, RecordType.Name = "New Order Assistance/Special Terms"), Estimated_Completion_Date2__c, Estimated_Completion_Date1__c))

Thanks please help me it is very urgent
  • March 24, 2015
  • Like
  • 0
I keep getting this error message in my developer console, but I'm not sure why.

trigger Trigger_UpdateWarranties on Unit__c (after delete, after insert, after update) {
    
    if (trigger.isdelete)
       delete [select id from Warranty__c where product__c in :trigger.oldmap.keyset()];
    if (trigger.isinsert || trigger.isupdate)
    {
         map<id,Warranty__c> mapw = new map<id,Warranty__c>([select id,product__c from Warranty__c where product__c in :trigger.newmap.keyset()]);
         list<Warranty__c> lsw = new list<Warranty__c>();

          for (unit__c u : trigger.new)
           {
              boolean exist = false;
                 for (Warranty__c w : mapw.values)
                {
                    if (u.id == w.product__c)
                    {
                        exist = true;
                        break;
                     }
                     //may enhance your logic here
                  }
              if (!exist)
              {
                   Warranty__c w1 = new Warranty__c();
                   w1.Commercial_Parts__c = Warranty__c.Commercial_Parts__c;
                   lsw.add(w1);
               }
    }
       if(lsw.size() > 0)
        insert lsw;
    

    }
}
  • March 31, 2015
  • Like
  • 0
Hi Guys,

I'm using a formula field to replicate the value of another field, but also to remove the first two characters if they equal "00", I'm having trouble with this, problem being it removes "00" regardless of where it is positioned. Example below;

Original value: 007985887100
What i currently get back: 79858871
What i would like to get back: 7985887100

Any help would be much appreciated.

Thanks
Lorenzo
 
Hi expert,

I have trigger below and it got soql exception. I just join project few days so I do not understand the logic of the flow. Can any one advise to improve the code. I see SOQL in for loop:
     if (Trigger.isInsert) {
                
                LineItemFormController.isInsertTrigger = true;
                for(Line_Item__c item :Trigger.New){
                if ((lineItemRecordType != '') && (item.Cloned_Line_Item__c == null) && (item.RecordTypeId == lineItemRecordType)) {
                    lineItemIds.add(item.Id);
                    if (lineItemMaps.get(item.Id) == null) {
                        lineItemMaps.put(item.Id, new List<Line_Item__c>());
                    }
                    }
                }
                
                List<Line_Item__c> oldAuditLineItems = [SELECT Id,Line_Item__c, Active__c, Line_Item_Status__c
                                                    FROM Line_Item__c
                                                    WHERE RecordTypeId =:auditRecordType
                                                    AND Active__c = true
                                                    //US5105
                                                    AND Line_Item_Status__c != 'Audited'
                                                    AND Line_Item__c IN :lineItemIds
                                                   ];
                for (Line_Item__c auditItem : oldAuditLineItems) {
                    lineItemMaps.get(auditItem.Line_Item__c).add(auditItem);
                }
                System.Debug('nghiatran: Insert ' + isUpdate);
                System.Debug('vinhvinh: Come to Insert Audit trigger');
                for(Line_Item__c item :Trigger.New){
                    Line_Item_Type__c lineItemType  = [SELECT Id,Line_Item_Category_Text__c,Line_Item_Type_Aggregated_Category__c,Name FROM Line_Item_Type__c where id =: item.Line_Item_Type__c limit 1];
                    if ((item.Cloned_Line_Item__c == null) && (item.RecordTypeId == lineItemRecordType)) {
                        // US6137 insert start
                        system.debug('nghiatran lineItemType.Line_Item_Type_Aggregated_Category__c ' + lineItemType.Line_Item_Type_Aggregated_Category__c);
                        if(lineItemType.Line_Item_Type_Aggregated_Category__c == 'Electoral Expenditure' ||
                            lineItemType.Line_Item_Type_Aggregated_Category__c == 'Small Donations Made' ||
                            lineItemType.Line_Item_Type_Aggregated_Category__c == 'Small Donations Received')
                            return;
                        // US6137 insert end
                       if (lineItemMaps.get(item.Id).size() == 0 ) {
                           system.debug('nghiatran access insert after ' + lineItemType.Line_Item_Type_Aggregated_Category__c);
                            Line_Item__c temp = item.Clone(false,true);
                            temp.Line_Item__c = item.Id;
                            temp.Line_Item_Type__c = item.Line_Item_Type__c;
                            temp.RecordTypeId = auditRecordType;
                            temp.Active__c = true;
                            temp.Line_Item_Status__c = 'Not Audited';
                            newAuditLineItems.add(temp);
                        }
                    }
                }
            }
I have a following trigger to update the record type lookup. I'm taking value from the text field and trying to update lookup but its not working. can someone please help?
 
trigger UpdateLookup on Manager__c (after insert, after update) {
try {
set<string> rtset = new set<string>();
for (Manager__c inq : trigger.new) {
   rtset.add(inq.Record_Type__c);
}

Map<String, RecordType> rtmap = new Map<String, RecordType>([Select id from RecordType Where Name in :rtset]); 



for (Manager__c inq : trigger.new) {
     inq.RecordTypeId = rtmap.get(inq.Record_Type__c).id;
   
     
  
}
} catch(Exception e) {  
}
}

 
  • March 31, 2015
  • Like
  • 0
Hi, I'm having some issues putting together a formula that will sum the total for values inserted in the Potentialsales__c field across a number of records (only the values that are listed in salesprob__c of "70%+" should be included in the calculation) 

Potentialsales__c is a currency field, salesprob__c is a picklist with multiple values

to explain myself better; say 5 records currently have entries for Potentialsales__c and salesprob__c as follows;

Account A: Potentialsales__c: $100,000 / salesprob__c: 40%
Account B: Potentialsales__c: $110,000 / salesprob__c: 70%+
Account C: Potentialsales__c: $120,000 / salesprob__c: 30%
Account D: Potentialsales__c: $130,000 / salesprob__c: 10%
Account E: Potentialsales__c: $140,000 / salesprob__c: 70%+
Account F: Potentialsales__c: $150,000 / salesprob__c: 10%
Account G: Potentialsales__c: $160,000 / salesprob__c: 60%
Account H: Potentialsales__c: $170,000 / salesprob__c: 10%
Account I: Potentialsales__c: $180,000 / salesprob__c: 70%+
Account J: Potentialsales__c: $190,000 / salesprob__c: 30%

Ideally the formula should result pull in and sum only the values from accounts B, E and I and therefore display $430,000

Any help on this would be fantastic!
I am trying to print Account Name and related cotact name in the other columns of pageblocktable

<apex:page standardController="Account" extensions="CustAccContExtn" >
    <apex:form >
        <apex:pageBlock title="A/c and Cont in Table" >
            <apex:pageblockButtons location="bottom">
                <apex:commandButton value="Fetch Account" action="{!getAccountsResc}"/>
            </apex:pageblockButtons>
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!allAccs}" var="ac">
                    <apex:column value="{!ac.Name}" headerValue="Account Name"/>
                    
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

public class CustAccContExtn {
    
    public List<Account> allAccs {get;set;}
    
    public PageReference getAccountsResc() {
        allAccs = [SELECT id, Name FROM Account];
        return null;
    }
    public CustAccContExtn(ApexPages.StandardController controller) {
        allAccs =  new List<Account>();
    }
}


What update do I need to make on select statement to pull the name of all contact associated for an account and how do i call them in apex:column

Please Help!

 
  • March 29, 2015
  • Like
  • 0
How to create more than 14 days Event record?

EX: i want run 6 months continually, but Salesforce allow max 14day,so how to split the date and creating multipule events

Any body help me...
Thanks,
Is it possible to pull through a merge field to the HPYERLINK formula in a Formula (Text) field?

The link works in as a custom link/button eg. www.website.com/form?pa0={Contact.Email} - however this same link does not pull through the field, but treats the field merge it as text when used in a Formal (Text) fields as: HPYERLINK (www.website.com/form?pa0={Contact.Email}).

Any help ont his would be much appreciated.
Hi Guys,

I have developed a trigger to update parent record when a child record is changed.

here is the trigger for that:



trigger Updateoffercomms on pba__Closing__c (after update) 
{   if(Trigger.IsUpdate)  
 {            Set<String> offerids= new Set<String>();                
 for (pba__Closing__c cl : Trigger.new)      
      {       
       if( (cl.Run_Updateoffercomms__c != Trigger.oldMap.get(cl.Id).Run_Updateoffercomms__c))         
           {                    if(cl.Run_Updateoffercomms__c == true)           
                                    offerids.add(cl.pba__Offer__c);                
             }
  }            List<pba__Offer__c> offers= [SELECT Id,First_Commission__c, first_Commission_Date__c,Second_Commission__c,Gross_Commission__c FROM pba__Offer__c WHERE Id =: offerids];        
 Map<String, pba__Closing__c> cprmap = new Map<String, pba__Closing__c>();        

for (pba__Closing__c cl : Trigger.new)
{                         
 cprmap.put(cl.pba__Offer__c, cl);         
}                           
       for (pba__Offer__c o : offers)      
          {       
             if (cprmap.containsKey(o.Id))       
                   {                        
                      o.First_Commission__c  =  cprmap.get(o.Id).X1st_Commission_Amount_payable__c;                        o.first_Commission_Date__c = cprmap.get(o.Id).Date_when_Contract_went_unconditional__c;         o.Second_Commission__c = cprmap.get(o.Id).X2nd_Commission_amount_payable__c;       o.Gross_Commission__c = cprmap.get(o.Id).Gross_Commission_Available__c;                                  
}   
  }   
update offers;  
 }
}


and the test class for this is :

@isTest
private class Mycprtest2
{

    static testMethod void cprtriggertest2()
    {
    
    contact c = new Contact(FirstName = 'Yams1', LastName = 'Bat');
    insert c;
    pba__Listing__c L = new pba__Listing__c(RecordTypeId = '01290000000rIhl',Name = 'tess3' , pba__Address_pb__c = '66 cotterell rd' ,pba__City_pb__c = 'Petrie');
    insert L;
    pba__Offer__c o = new pba__Offer__c(pba__Listing__c = L.id ,pba__Contact__c = c.id);
    date dtend = Date.newInstance(2015, 31 , 03);
     pba__Closing__c cl = new pba__Closing__c(pba__Offer__c = o.id);
        insert cl;
        cl.Run_Updateoffercomms__c = true;
        cl.X1st_Commission_Amount_payable__c = 90;
        cl.X2nd_Commission_amount_payable__c = 68;
        cl.Gross_Commission_Available__c = 78909;
        cl.Date_when_Contract_went_unconditional__c = dtend;
        
  update cl;
 
       
}
}

The problem here is my trigger is only getting 68% coverage. Any ways to improve it?
Any help is greatly appreciated.

Thanks in advance.
 
  • March 26, 2015
  • Like
  • 0

Hi ,

I need to Disable trigger in Production Environment in order to carry on some things. But I dont have Access to Sandbox.

In google they said, We need to disable in Sandbox first which in my Case i can't...

Any other ways?

Thanks.

The situation is, when Stage is equals to "Closed Won" or "Closed Lost" 3 Multi-Picklist must never be blank.

How can I make a rule where the 3 multi-picklist must not be blank, when the values of Stage is Closed (Won & Lost).

i tried multiple attempts with AND, OR, ISPICKVAL, etc.
------
Sample 1:
AND
(
OR
(
ISPICKVAL( StageName , "Closed Won"),
ISPICKVAL( StageName , "Closed Lost")
)
OR
(
ISBLANK(MultiPicklist1__c),
ISBLANK(MultiPicklist2__c),
ISBLANK(MultiPicklist3__c)
)
)
-----
Sample 2:
AND(
NOT(ISNEW()),
ISBLANK(MultiPicklist1__c), 
ISBLANK(MultiPicklist2__c), 
ISBLANK(MultiPicklist3__c),
StageName = 'Closed Won','Closed Lost')
)

Advance thank you for the response.
We are not able to deploy classes into Production because of code coverage. But the code coverage of Production is 78% right now, we have also complied the classes and cleared all histrory related to Running test classes. What whould be the issue ?
Hi, 

Please halp me with a problem I am having. Here is what I want to happen: from the Task which is assigned to me I click a button and I get to an Opp create wizard and some of the fields are pre-populatd using values form that Task. I am having some success, but am stuck at one point. 

First of all my Task has 4 custom fields wich I want to grab and use their values to pre-populate fileds on an Opp. User-added image

Now, I created a new button and placed it on the Task layout. The button is Detail Page Button and I am trying to use "URL Hack" to pre populate some of the fields. Here is the code for my button 
/006/e?
ent=Opportunity
&nooverride=1
&RecordType=012U0000000ZW7x
&00NU0000003aXaU=New
&opp4={!Account.Name}
&CF00NU0000003aZwA ={!Contract.Id}
&00NK0000001jB5V = {!Task.Type}      // custom field 
&00NK0000001jB5G = {!Task.Marketing_Activity_Name__c}   // custom field 
&00NK0000001jB5L = {!Task.Last_Referrer__c}   // custom field 
&00NK0000001jB5Q = {!Task.Offer_ID__c}   // custom field 
&retURL=%2F006%2Fo

As you can see I have 4 new fields on an Opportunity Object to accomodate the mapping, I grab their IDs and try to force task field values on them. 

Now the stange part. When I click on the "Create Opportunity" button it does take me to the Opp create wizard and my fields are blank, BUT the Opp wizard URL shows that values are there.

User-added image

Here is the full URL I get once on the Opp create wizard page:
https://cs9.salesforce.com/006/e?ent=Opportunity&nooverride=1&RecordType=012U0000000ZW7x&00NU0000003aXaU=New&opp4=Test+Account+05&00NK0000001jB5V%20=%20Outbound+Prospecting&00NK0000001jB5G%20=%20Marketo+Push+2&00NK0000001jB5L%20=%20www.wsj.com&00NK0000001jB5Q%20=%209876543210&retURL=%2F006%2Fo

Any ideas what might be causing this behaviour? I am completely lost. My "URL Hack" works for some othe fields, but not for these. 

Any input will be appreciated.
I am new to attempting apex triggers and just starting out.  I need a VERY SIMPLE, BASIC apex and I've spent hours reading through complex examples and not finding anything for what I need.  Here's my case, could anyone help?

2 Objects:  Contact (standard) and Offer (custom).

The Offer object has a lookup field to the Contact which is selected manually by the user.  
I created a custom lookup relationship field on the Contact called "Offer record."

What I want is an apex that when an Offer is created, the apex will lookup that Contact and populate the Offer record onto the field "Offer record."  

Using abbreviated examples:  So I create record OFR-2468 and using the lookup field choose Contact Joe Smith. I click save on the Offer record.  The apex should go to Joe Smith's Contact record and populate his field "Offer record" with the same offer just created, "OFR-2468."  So you could click back and forth between the two and I could write formula fields on the Contact if I need to.  

I am not concerned if there are multiple records created for the same contact or anything special.  I don't need special criteria or conditions.   Just a reverse lookup to populate that object record and if that is successful I can think about getting more complex.

I appreciate any help you could give.  Thanks in advance.
 
Hi Guys,
Can you please help me out with this formula field.
IF Submission_Date__c <> NULL AND Record Type Name = "Account Number Issue" then show me Estimated_Completion_Date3__c
IF Submission_Date__c <> NULL AND Record Type Name = "New Order Assistance/Special" Terms then show me Estimated_Completion_Date3__c
IF Record Type is other than these 2 then and Submission_Date__c <> NULL it should show Estimated_Completion_Date1__c

I am trying this code below but it is not giving me the right Date. It is showing Estimated_Completion_Date1__c in all the Record Types

IF(AND(Submission_Date__c <> NULL, RecordType.Name = "Account Number Issue"), Estimated_Completion_Date3__c
IF(AND(Submission_Date__c <> NULL, RecordType.Name = "New Order Assistance/Special Terms"), Estimated_Completion_Date2__c, Estimated_Completion_Date1__c))

Thanks please help me it is very urgent
  • March 24, 2015
  • Like
  • 0