• 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'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

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??

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?