• Manos Spanoudakis
  • NEWBIE
  • 55 Points
  • Member since 2010
  • Salesforce Technical Architect
  • Nefos GmbH


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 27
    Replies

Hi,

 

  I am writting a triigger to update values based on the picklist value. 

 

 There is a fields Renewal which has picklist of ( Yes and No ) based on the pick list value another field will get updated which is Discount Program

 

 My Requirement now is Discount Program must set value only for first time next time it must not set 

 

  i.e if user select Renewal (Yes) for first time it must set Discount Program to DSP next time when your select No or Yes from Renewal it must set to NSP

 

 These two fields are on Oppertunities,   Renewal_c and Discount_c

 

 

trigger NewDiscountProgramUpdate on Opportunity (before update) 
{
// Loop through the incoming records
for (Opportunity o : Trigger.new) {

 if ( o.Renewal_Opportunity__c == 'Yes' && 
      o.discount_program__c ==  'NSP' ) 
  {
    o.discount_program__c = 'DSP';
  }
 else
      {
    o.discount_program__c = 'NSP';
  }

}

Please Suggest me

 

 

  

I want to search Accounts which contains underscores, suppose I have accounts with names test,test_123,test_test,test_456 and when i fire following query it is returning me 4 rows where it should return 3only.

 

Query :

   select id from account where name like  '%test_%'

 

Salesforce considers ( _ ) as any single charatcter and thats why it is returning me 4 rows is there any way to overcome this. I have tried using escape sequence '%test\_%' but it is also not working.

 

Any pointers??

  • February 05, 2013
  • Like
  • 0

hi all, 

 

Since the activation of a critical update (Block custom links or custom buttons that contain invalid URLs) we are not able to use any Custom Button using the URLFOR function ! 

 

Buttons are still in page layouts but yet inactive ! 

 

For example this (List button type URL) 

 

{!URLFOR($Action.Account.New,Opportunity.Id,[retURL="Account.Id"])} 

 

doesn't work ! 

 

Any hints ? 

 

Thanxxx

Hi All,

 

I am getting the following Exception from a trigger that was till now functioning with no problem !

 

The trigger is a very simple one, deleting AccountShares when an Account_Team record is deleted...

 

I am getting the SELF_REFERENCE_FROM_TRIGGER exception and I really cannot understand why...

Any help would be really appreciated !

 

The debug log is the one I am getting when I try to delete one Account_Team record.

=============================

trigger trgAccount_Team_Before_Delete on Account_Team__c (before delete) {
      
        Set<ID> sAccId=new Set<ID>();
      Set<ID> sUId=new Set<ID>();
      for(Account_Team__c at:trigger.old){
        if (at.ftxt_AccOwnerID__c==at.User__c) continue;
        sAccId.add(at.Account__c);
        sUId.add(at.User__c);
      }
      ClsAccount_Team.syncDeletedAccountSharing(sAccId,sUId);
}

 

 

//----ClsAccount_Team.syncDeletedAccountSharing Code-----

    public static void syncDeletedAccountSharing(Set<ID> sAccId,Set<ID> sUId){
        delete [Select Id From AccountShare Where UserOrGroupId In: sUId And AccountId In: sAccId AND RowCause='Manual'];
    }

 

======DEBUG LOG=========

 

16.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO 10:38:15.291|EXECUTION_STARTED 10:38:15.291|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS 10:38:15.291|CODE_UNIT_STARTED|[EXTERNAL]|01q200000000Fyi|trgAccount_Team_Before_Delete on Account_Team trigger event BeforeDelete for [a0G2000000Q1Z5R]

 

10:38:15.292|METHOD_ENTRY|[8]|SET.add(ANY) 10:38:15.292|METHOD_EXIT|[8]|SET.add(ANY) 10:38:15.292|METHOD_ENTRY|[9]|SET.add(ANY) 10:38:15.292|METHOD_EXIT|[9]|SET.add(ANY) 10:38:15.292|METHOD_ENTRY|[11]|01p20000000DuDc|ClsAccount_Team.syncDeletedAccountSharing(SET, SET) 10:38:15.293|SOQL_EXECUTE_BEGIN|[94]|Aggregations:0|Select Id From AccountShare Where UserOrGroupId In: sUId And AccountId In: sAccId AND RowCause='Manual'

 

10:38:15.415|SOQL_EXECUTE_END|[94]|Rows:1 10:38:15.415|DML_BEGIN|[94]|Op:Delete|Type:AccountShare|Rows:1

10:38:17.040|DML_END|[94]

10:38:17.041|EXCEPTION_THROWN|[94]|System.DmlException: Delete failed. First exception on row 0 with id 00r2000002JUOctAAH; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0G2000000Q1Z5R) is currently in trigger trgAccount_Team_Before_Delete, therefore it cannot recursively delete itself: [] 10:38:17.042|METHOD_EXIT|[11]|ClsAccount_Team.syncDeletedAccountSharing(SET, SET)

 

10:38:17.042|FATAL_ERROR|System.DmlException: Delete failed. First exception on row 0 with id 00r2000002JUOctAAH; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0G2000000Q1Z5R) is currently in trigger trgAccount_Team_Before_Delete, therefore it cannot recursively delete itself: [] Class.ClsAccount_Team.syncDeletedAccountSharing: line 94, column 3 Trigger.trgAccount_Team_Before_Delete: line 11, column 7

 

10:38:17.042|CUMULATIVE_LIMIT_USAGE 10:38:17.042|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 1 out of 20 Number of query rows: 1 out of 1000 Number of SOSL queries: 0 out of 0 Number of DML statements: 1 out of 20 Number of DML rows: 1 out of 100 Number of script statements: 7 out of 10200 Maximum heap size: 0 out of 3000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 100 Number of record type describes: 0 out of 100 Number of child relationships describes: 0 out of 100 Number of picklist describes: 0 out of 100 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 0 Number of System.runAs() invocations: 0 out of 20 10:38:17.042|CUMULATIVE_LIMIT_USAGE_END 10:38:17.042|CODE_UNIT_FINISHED|trgAccount_Team_Before_Delete on Account_Team trigger event BeforeDelete for [a0G2000000Q1Z5R]

Hi,

 

  I am writting a triigger to update values based on the picklist value. 

 

 There is a fields Renewal which has picklist of ( Yes and No ) based on the pick list value another field will get updated which is Discount Program

 

 My Requirement now is Discount Program must set value only for first time next time it must not set 

 

  i.e if user select Renewal (Yes) for first time it must set Discount Program to DSP next time when your select No or Yes from Renewal it must set to NSP

 

 These two fields are on Oppertunities,   Renewal_c and Discount_c

 

 

trigger NewDiscountProgramUpdate on Opportunity (before update) 
{
// Loop through the incoming records
for (Opportunity o : Trigger.new) {

 if ( o.Renewal_Opportunity__c == 'Yes' && 
      o.discount_program__c ==  'NSP' ) 
  {
    o.discount_program__c = 'DSP';
  }
 else
      {
    o.discount_program__c = 'NSP';
  }

}

Please Suggest me

 

 

  

I'm curious to know how some of the code in my organization is working and was deployed as the code coverage is less than 75% for many of the triggers/controllers.  

 

I see that the creation date for most of the code is 2011.  Is this a recent requirement Salesforce implemented? (i've only been working with SFDC for about 4 months).  I know if I deploy code with less then 75% coverage, the code will not deploy. 

 

It would make sense to me that SFDC implemented this requirement and allowed code in production to continue to run even though the coverage was less than 75% but going forward would force developers to meet the requirement.  Any insight that can be provided would be of great benefit to me. Thanks!!!

 

 

Hi 

 

we have a validation rule on Lead object ,we need to make  this validation rule as inactive like do not fire in the trigger which is on task object .the trigger is copying some field values from task  to the lead object.

 

Thanka in advance

  • April 10, 2013
  • Like
  • 2

I'm trying to get the same ownerID from task "test 1" to task "test 3" when I complete the task "test 2".

 

trigger CriarTarefa_Impressao_e_Nova_separacao on Task (before update) {
      
  List<Id> ownerIds = new List<Id>();
  for (Task task : Trigger.new) {
    if (task.subject == 'test 1') {
      ownerIds.add(task.ownerId);
    }
  } 
    
    List<Task> owners = [SELECT Id, ownerId FROM Task WHERE ownerId IN :ownerIds];
  	Map<Id,String> ownerIdsTo = new Map<Id,String>();
  	for (Task owner : owners) {
    ownerIdsTo.put(owner.Id,owner.ownerID); 
  }
  
    List<Task> taskNova = new List<Task>();    
    for (Task task : Trigger.new)
    if (task.subject == 'test 2' && task.status == 'Completed'){
                taskNova.add (new Task(
                         Subject = 'test 3',
                         Status = 'Nenhum',
                         WhatID = task.WhatID,
                         Description = task.description,
                    	 Ownerid = ownerIdsTo.get(task.OwnerId),
                         ActivityDate = Date.today()));
    }

 

With this code the OwnerID returns null.

I have a page that retrieves an object ID from a parameter list. The problem is that when the object is deployed into a new instance from my sandbox or from one sandbox to another, the Id changes. I'd like to find a way that I can not have to add "magic strings" where I hard code the Id in the Apex code. This becomes painful when deploying because we have to maintain an ever growing list of classes that need to be changed after deployment.

 

I also have a similar problem with some URLs that point to other pages. Is there a repository I can query using the name of the page that will return the Id?

hi all, 

 

Since the activation of a critical update (Block custom links or custom buttons that contain invalid URLs) we are not able to use any Custom Button using the URLFOR function ! 

 

Buttons are still in page layouts but yet inactive ! 

 

For example this (List button type URL) 

 

{!URLFOR($Action.Account.New,Opportunity.Id,[retURL="Account.Id"])} 

 

doesn't work ! 

 

Any hints ? 

 

Thanxxx

I want to search Accounts which contains underscores, suppose I have accounts with names test,test_123,test_test,test_456 and when i fire following query it is returning me 4 rows where it should return 3only.

 

Query :

   select id from account where name like  '%test_%'

 

Salesforce considers ( _ ) as any single charatcter and thats why it is returning me 4 rows is there any way to overcome this. I have tried using escape sequence '%test\_%' but it is also not working.

 

Any pointers??

  • February 05, 2013
  • Like
  • 0

I've tried to bulkify this trigger but with no success, below is the code that works for single updates.  We use an object other than Opportunities to track our sales and I'm trying to build out a better way to track our ROI on campaigns.  This triggers goal is to get a sum of all sales for the 90 days after a campaign has ended on each campaign member record.  Any pointers?

 

 

 

 

trigger CMPostSales on CampaignMember (before update) {


Integer i = 0;

CampaignMember cm = Trigger.new[i];

// Current CampaignMember and Contact ID
String intCm = Trigger.new[i].Id;
CampaignMember cmm = [Select Contact.id, End_Date__c, Post_Sales__c from CampaignMember where id =: intCm];

//Step 2. Create a list of Transactions who are children of Contact record.
List<Transaction__c> t = [Select Transaction__c.Gross_Amount__c From Transaction__c WHERE Transaction__c.Rep__c =: cmm.Contact.id AND Transaction__c.Trade_Date__c >: cmm.End_Date__c AND Transaction__c.Trade_Date__c <: cmm.End_Date__c + 90];

/* Update Sales within the range of the campaign */
// Loop through the filtered Transactions and sum up their amounts.
    Double a = 0;
        for(Transaction__c tr : t)
            {
            if(tr.gross_Amount__c != Null)
                {
                a += tr.Gross_Amount__c;
                }
            }
        cm.Post_Sales__c  = a;
}

 

 

I scoured the message boards and don't see anyone else who has run into this.  I'm thinking it's a bug, although not a terribly detrimental one.

 

I have a "without sharing" class that needs to know if the current user has access to a list of records.  So it uses a separate "with sharing" class to figure it out... works well.  Then to take it one step further and see if they have access to edit you have to get creative, and the knowledge in this forum told me the only way is to attempt an update, see which records failed and then do a rollback to a savepoint... this too works well, woohoo.

 

The weird thing, is that the records that are updated in this check will then show up in the users recent items.  I could see how maybe this is a good thing if the records were actually updated... but they weren't the change was rolled back.  I guess it's a bug.. thoughts?