• venkat-D
  • SMARTIE
  • 1108 Points
  • Member since 2012

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

I want to query get the values from the already queried result dynamically
I have below snippet
for (QuoteLineItem q : qli){
                String a = 'Designation__c';
                if(String.isNotBlank(q.Designation__c)){  //Work
                            
                }
				if(String.isNotBlank(q.a)){        //Doest not Work
                            
                }
            }
Can anyone tell me, how could i resolve this issue 

thanks for advise
 
Can someone help me in writing a single query to retrieve old data and new data for the oparticular condition in if satatement?

List Account accs = Trigger.newMap.keySet() ;

 for (Account a : accs)
            if (a.RecordTypeID == '012D00000002qdE' && a.R_seau_int_gr__c == true && a.Etat_relation_GEO__c == 'Déploiement' && (oldmap == null || oldMap.get(a.Id).Etat_relation_GEO__c != 'Déploiement'))
            {
                hasHierarchy = true;
                accIds.add(a.id);
                while (hasHierarchy)
                {
                    List<Account> res = [SELECT id, Etat_relation_GEO__c FROM Account WHERE Etat_relation_GEO__c != 'Terminé' AND parentId IN :accIds];
                    accIds.clear();
                    if (res == null || res.size() == 0)
                        hasHierarchy = false;
                    for (Account aa : res)
                    {
                        accIds.add(aa.id);
                        toUpdate.add(aa);
                    }
                }
            }
 
  • August 16, 2017
  • Like
  • 0
Hello World!
I have a use case that requires a trigger and it sounds about as simple as it gets. We have an external application called BrightTALK integrated with our Salesforce org. Trouble is, we use State and Country Picklists and BrightTALK tries to push Leads into our Salesforce org with Country names that do not match the countries in our Salesforce org. As far as I know, there are two ways to tackle this issue. 1) Change the list of Countries in our Salesforce org. 2) Write a before trigger, which, if I understand correctly, could change a Country value like "China (Hong Kong)" into "China", which our org would then accept because the value matches a value in our State and Country Picklists setup.

I have never written a trigger before, and I took one programming class 10 years ago. Does anyone have any recommended places to start, sample code to look at, reference material to refer me to where I can see the methods available to me in an before trigger and learn some syntax? Any help is much appreciated.
I need to know the instance number for an external integration. It's not in my Salesforce URL because I have a custom domain. Is there a way I can look this up or query in dev console?
HI All,
I have a junction object called locationcontact which is related to location (masterdetail) object and contact(masterdetail).Below the location a related list is placed to enter a location contact .I need to restrict if the user tries to assign a same contact to location (means avoid duplication of same contact to location).I am writing a trigger to solve this ,but unable to fetch rows.

trigger duplocationcontact on location_Contact__c (before insert) {
    
    for (location_Contact__c ci : trigger.new) {
            
        List<location_Contact__c> resultList = [SELECT id FROM location_Contact__c WHERE  location__c = :ci.location__c    AND Contact__c = :ci.Contact__c.name];
                 
        if (!resultList.isEmpty()) {
              
        ci.addError('Duplicate record, a location contact already exists');
        }
        }
}
This has happened in a number of different flows and I cant pinpoint how to prevent it.  Here is an example:
"The flow failed to access the value for myVariable_current.Content_Editor_Contact__r.Id because it hasn't been set or assigned."
This error is occuring in a flow...but in the flow criteria I have the folllowing line:

"[Account].Content_Editor_Contact__r.Id Is null Boolean False"

I thought that would prevent the flow from attempting to complete the Action if the Content_Editor_Contact__r.Id field was empty...but instead it is causing the flow to error and the user is unable to save the record that started the flow.  The desired behavior is that if the Content_Editor_Contact__r.Id is empty, the flow should simply stop and do nothing else - not throw an error and prevent the user from progressing.
Hi,

I am very new to Apex and need some help. I created an Apex trigger to run on a custom object that checks a box when a file is uploaded and unchecks a box when the file is removed. I manually tested it which worked and uploaded it to my production org, but found out that my code needs 75% testing coverage. I created a Test class but I'm getting 0% code coverage. Here is my Trigger:
 
trigger imaUp on Attachment (after insert, after update, after delete) {
	if(trigger.isInsert || trigger.isUpdate){
		List<IMA__c> co = [select id, Uploaded__c from IMA__c where id =: Trigger.New[0].ParentId];
			if(co.size()>0) {
				co[0].Uploaded__c = true;
				update co;
			}
	}
	if(trigger.isDelete) {
		List<IMA__c> co1 = [select id, Uploaded__c from IMA__c where id =: Trigger.old[0].ParentId];
			if(co1.size()>0) {
				co1[0].Uploaded__c = false;
				update co1;
            }
	}
}


And here is my Test Class:
@isTest
public class imaUpTest {
    @isTest static void test_method_one() {
      IMA__c co = new IMA__c();
        co.Date_Sent__c = Date.today();
        co.Date_Signed__c = Date.today();
        co.Entity__c = 'Test';
        co.Status__c = 'Signed';
        co.Uploaded__c = TRUE;
        insert co;
	  Attachment attach = new Attachment();
        attach.Name = 'TestFile';
        attach.parentId = co.id;
        insert attach;
    }
}


Once complete will I also have to reupload my code into my production org?

Thanks!
Hello, 

I am trying to deploy a class that will allow me to group my StageName= Qualified opportunities by a custom field called vertical__c.

However, I am running into a code coverage error when trying to deploy this, as the new class is bringing my code coverage down to 73% and I admitadlly do not know near enough about test methods to bring this up.  Can anyone help?

Here is my class: 
 
public with sharing class QualOpController
{

public List <Opportunity> Opty {get;set;}
public list<String> campaigns {get;set;}

public void load() 
{
  campaigns= new List<String>();
  Opty = [Select id, name, Company_Name__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Qualified' ORDER BY Probability DESC]; 
  
  Set<String> campaignSet = new Set<String>();
  for (Opportunity j : Opty)
      campaignSet.add(j.Vertical__c);
      
      for (String campaign : campaignSet) 
      {
            campaigns.add(campaign);
      }
      campaigns.sort();
    }
}

and here is the test class that I have for it... please don't laugh: 
 
@isTest(seeAllData = false)
public class QualOpControllerTest{
    // Unit test Method
    static testmethod void UnitTest() {
        //Create your opportunity record with required field
        //Opportunity j = new Opportunity(StageName = 'Qualified');
        //insert j;
        test.startTest();
            QualOpControllerTest qo = new QualOpControllerTest();
        test.stopTest();
    }   
}

What is the best way for me to sure up this test?

Thanks in advance!

John
I have written a Controller for searching data on visualforce page. below is the controller.
public with sharing class Condosearchcontroller { 
   public Condosearchcontroller() {

    }

    public list <Condo__c> Cond {get;set;}  
    public string beds {get;set;} 
    public string baths {get;set;}
    public string squarefootage {get;set;} 
    public Condosearchcontroller(ApexPages.StandardController controller) {  
   }  
   
   public void search(){
   if (squarefootage == null){
    string searchquery='select name,Beds__c,Baths__c,Square_Footage__c from Condo__c where Beds__c = '+beds+' and Baths__c = '+baths+''; 
        Cond = Database.query(searchquery);
      }
      else { 
      string searchquery1='select name,Beds__c,Baths__c,Square_Footage__c from Condo__c where Beds__c = '+beds+' and Baths__c = '+baths+'and Square_Footage__c = '+squarefootage+'';
      Cond = Database.query(searchquery1);
}
}

when i enter data in all the 3 fields beds,baths,square footage. i am getting results.
but when i enter only beds,baths in visual force page.then i am getting error.
I'm trying to create a validation rule that prompts users from transferring Account records to system admin. 

This VR seems to prompt all users from transferring account records to one another, but I still want users to transfer records to one another, but not to System Admin. 

Any ideas? 
AND(ISCHANGED(OwnerId), 
NOT($Profile.Name ="System Administrator") 
)
User-added image
 
Hi All, 

I'm very proud of my first trigger :), but I'm sure that it could be improved considerably.  Could anyone assist? It works, but I will still need another trigger on the Opportunity Product (as it only works on update and not on insert). ...and I'm sure I missed out on some basics as this is my first shot.

What the code does:  Updates a field (Duration) on the opportunity products based on a field on the opportunity line item (phase) and 3 fields on the opportunity (dur_nnCMRR_1, _2,or _3)

trigger UpdateDurations on Opportunity (after update) 
//removed after insert as opps don’t have any product line when they are first created//
{for(Opportunity opp: Trigger.new)
{Opportunity oldOpp = Trigger.oldMap.get(Opp.Id);
if(oldOpp.Dur_2_nnCMRR__c != Opp.Dur_2_nnCMRR__c )                              
{ List<OpportunityLineItem> children = [ SELECT Id, OpportunityId, Duration__c,Phase__c from 
  OpportunityLineItem where OpportunityId = :Opp.Id AND Phase__c='Evaluation'];
  List<OpportunityLineItem> newids = new List<OpportunityLineItem>();
        for(OpportunityLineItem LI: children)
        {if(LI.Duration__c != Opp.Dur_2_nnCMRR__c)
        {LI.Duration__c = Opp.Dur_2_nnCMRR__c;newids.add(LI);}}
         if (newids.isEmpty()== false)
         {update newids;}} 
if(oldOpp.Dur_1_nnCMRR__c != Opp.Dur_1_nnCMRR__c )                                 
{ List<OpportunityLineItem> Install = [ SELECT Id, OpportunityId, Duration__c,Phase__c from 
  OpportunityLineItem where OpportunityId = :Opp.Id AND Phase__c='Installation'];
  List<OpportunityLineItem> newids = new List<OpportunityLineItem>();
        for(OpportunityLineItem LI: Install)
        {if(LI.Duration__c != Opp.Dur_1_nnCMRR__c)
        {LI.Duration__c = Opp.Dur_1_nnCMRR__c;newids.add(LI);}}
         if (newids.isEmpty()== false)
         {update newids;}}
if(oldOpp.Dur_3_nnCMRR__c != Opp.Dur_3_nnCMRR__c )                                 
{ List<OpportunityLineItem> Use = [ SELECT Id, OpportunityId, Duration__c,Phase__c from 
  OpportunityLineItem where OpportunityId = :Opp.Id AND Phase__c='Usage'];
  List<OpportunityLineItem> newids = new List<OpportunityLineItem>();
        for(OpportunityLineItem LI: Use)
        {if(LI.Duration__c != Opp.Dur_3_nnCMRR__c)
        {LI.Duration__c = Opp.Dur_3_nnCMRR__c;newids.add(LI);}}
         if (newids.isEmpty()== false)
         {update newids;}}}}
 
I'm trying to create a custom button that will appear on every case. It will allow the current user to click it and take ownership of the case.

This is the code I'm using (which I basically copied from the button I have for this same purpose on the Contact):
 
{!requireScript("/soap/ajax/33.0/connection.js")} 

var case = new sforce.SObject("Cases"); 
case.id = '{!Case.Id}'; 
case.ownerId= '{!$User.Id}'; 
var result = sforce.connection.update([case]); 

if (result[0].success=='false') {
     alert(result[0].errors.message);
} else {
     location.reload(true);
}

When I click the button, I get the error: "Unexpected token case"

Anyone know what I'm doing wrong here?

Thanks!
I'm trying to create a workflow rule that looks at Account Status.  If the Account Status was Hold and then becomes any other value, I want it to fire off an email.  I used AND(ISPICKVAL(PRIORVALUE( Account_Status__c ),'Hold')) but it fires everytime a record with Status Hold is edited.
What am I doing wrong.
Hi everyone,

I am wondering if there is a way to implement such task:
The need is to have in a custom object, let's say a "memo of a call", in which there exists a field where the several opportunities (already existing/inserted in Opportunities) are mentioned?

Any help would be great!


Thanks,
Skender
I am trying to make a validation rule to go along with my apporval process.  I need to lock the stagename pick list for 3 of my stages below. The code I have kinda works. I just can not save any opportutiny that is within that stage. 

My question is: how do I make the validation rule where as once the opportunity is in that stage (after apporval) the validation turns off for that stage so I can modify and save that opportunity.

AND(
$Profile.Name <> "System Administrator",
OR(
ISPICKVAL(StageName, "Pursue"),
ISPICKVAL(StageName, "Target"), 
ISPICKVAL(StageName, "Bid")
))
Hello,

I'm learning Apex and one thing I've come across is storing multiple sobject types in a List. For example:

List<Contact> myList = [SELECT ID, AccountID, FirstName, LastName, Account.Name FROM Contact];

In the above ID, AccountID, FirstName, and LastName are all fields from Contact so if I system.debug myList I will see these 4 fields. I won't however see the Account.Name field. Makes sense since the Account Name is from the Account object.

Couple of questions:

1. Since myList is of type Contact I was assuming that it wouldn't be able to store any fields that aren't from Contact. How is it that Account.Name is able to be stored in a Contact List?
2. How do I extract the Account Name from each of the records stored in myList? When I perform a SOQL query in Query Editor I see the Account Names there. But I'm at a loss as to how to extract the Names via Apex.

Thanks,

Mike
Hi,

I have a checkbox field on my opportunity object which I'm trying to reference in the filter logic section of the report builder, however the field isn't showing up and I can't figure out how to access the field programmaticaly (or even if that's possible). My ultimate goal is to filter a report on Tasks based on whether or not the opportunity that the task is attached to has this checkbox field checked. Any help would be much appreciated.

Thanks in advance,

Will
Hi,
I have a custom object topics__c. I need to create a custom field which has lookup to Event/Activities object. Whether that is possible?
Because i cant find Event object when i create a custom lookup field.

Thanks
Vivek
Hi,
I am trying to create a new unit test for a trigger I am creating based on this example. 
https://developer.salesforce.com/docs/atlas.en-us.196.0.sos.meta/sos/service_cloud_guides-auto_case_pop.htm
trigger SOSCreateCaseCustom on SOSSession (before insert) {
    List<SOSSession> sosSess = Trigger.new;
    for (SOSSession s : sosSess) {
        try {
            Case caseToAdd = new Case();
            caseToAdd.Subject = 'SOS Video Chat';
            if (s.ContactId != null) {
                caseToAdd.ContactId = s.ContactId;
            } else {
                List<Contact> contactInfo = [SELECT Id from Contact WHERE Email = :s.AppVersion];
                if (!contactInfo.isEmpty()) {
                    caseToAdd.ContactId = contactInfo[0].Id;
                    s.ContactId = contactInfo[0].Id;
                }
            }
            insert caseToAdd; s.CaseId = caseToAdd.Id;
        }catch(Exception e){}
    }
}

Here is the unit test I created for the trigger.
@isTest
private class SOSCreateCaseCustomTest {
	static testMethod void validateSOSCreateCase() {
        init();
        Test.startTest();
        
        String caseSubject = 'SOS Video Chat';
        
		// set up case to add 
        Case caseToAdd = new Case(Subject='SOS Video Chat');
        insert caseToAdd;
        
		Case ca = [SELECT Subject, ContactId from Case where Subject =: caseSubject];
		System.assertEquals(caseSubject, ca.Subject);
        
        Test.stopTest();
	}
}

The unit test doesn't seem to test against the trigger I created above. How can I map this unit test to the trigger? Thanks.
 
Hi Team,
 I have a custom field on task object.
 Whenever, there is a change in Case custom field, i would like to update the custom field in task.
 Please let me know, to achieve it through trigger ..
  • March 04, 2016
  • Like
  • 0
Hi,
I have defined two record types (record type 1 and 2) in my salesforce instance to represent two separate business units.  On the contact object I have defined a unqiue field to make sure that the same contact cannot be inserted twice for a record type.  The problem I am running into is that if a contact exists with recrod type and I try to insert the same contact with record type 2, I get the error "duplicate values on record".  Is there a way to enforce the unqiueness of a field per recrod type?
I have a visual force page. I have two values on this page that I need to pass to its controller. I am able to put these values in hidden fields on the page. I am now trying to use an apex:actionFunction to send them over to the controller. 

Here is my relevant section of the VF Page.
<apex:actionFunction name="passStringToController" immediate="true" action="{!saveCaseRecord}" rerender="">
                        <apex:param name="p1" value="{!Case.Type}" assignTo="{!CaseType}" />
                        <apex:param name="p2" value="{!Case.Case_Type_Details__c}" assignTo="{!CaseSubType}" />
                    </apex:actionFunction>


Here is the relevant section of the apex controller code.
public PageReference saveCaseRecord()
{
            System.Debug('BeforE calling createCase');
            System.Debug('CaseType ' + CaseType);
            System.Debug('CaseSubType ' + CaseSubType);
}


I am definitely missing a piece here, because I am getting a null each time in the controller. I wrote a javascript function, but I don't believe it is firing. I am never getting the alert on my view page.
function passStringToController()
      {
        alert('We need to pass stuff from here');
      }

 
I have a custom object with default page layout. This object has 4 phone numbers.
My requirement is one of the numbers needs (*) beside it to denote preferred phone number.

eg:

home cell phone 362-589-5968 (*)            work cell phone 489-652-6954
home landline phone 563-965-5231          work desk phone 456-895-8954


I have a picklist where user chooses their preferred number. It could be home cell, work desk, etc.
Now I want to use that information to put star beside the right number.

I created a formula field to display (*), and added it to page layout. But this approach doesn't work for me because it displays its own field label, and is placed separate from the phone number, like this:

Preferred Phone (*)

How can I do this so that label is suppressed and (*) displays on the side of phone number?

Thank you!

Hello everyone,

So I want to set up a formula field for region that auto fills when opportunities are created from the accounts page. The only problem is we currently have a picklist field set up for region that is supposed to be filled out by the Account Manager (but rarely is, hence why i want to do this), but you cant turn a picklist field into a formula field. 

I want to create a new formula field that is "Account Region". Is there a way i can export all the current data and then create the new formula field, then import the data and have everything that was originally in "region" now be "account region". 

Any advice on how I can accomplish this would be much appreciated.

Thanks,
Frank

Hi there,

I've encountered a problem... My trigger (before insert/update) for Account page seems to work unexpectedly and so strangely.
According to Debug log, user A fired the trigger for over 1000 account pages within a few minutes but the user A didn't access/edit the account pages. Besides, the lastmodifiedby of these account pages indicated another user, user B who never access to the pages as well.

Here is my trigger which is for populating text field "IPs_Copy__c" to judge if the rick text field  "IPs__c" is updated or not.

trigger UpdateIPsCopy on Account (before insert, before update) {
    For (Account A:Trigger.new){
        if(A.IPs__c != null) {
             A.IPs_Copy__c = A.IPs__c.left(100) ;
            }
         return;
        }
}

This strange updates had happened almost everyday in my org until the trigger was deactivated. 
Any possible scenario which causes this kind situation or any advice on what I should do to find the factor of this strange situation??   
You kind advice would be highly appreciated.
 
This is my first attempt to deploy something from one sandbox to another.

All changes are on a custome Visualforce Opportunity page.

I have only added three new fields and removed some fields and related lists from the visualforce page. Although everything is working perfectly in the Sandbox 1 environment, when I deployed it to Sandbox 2 it does not look the same. In-line editing is no longer possible and these fields are missing from our "edit" visualforce page.

Am I missing something simple during the deployment process? It seems to me if:

1. Things are working in the Sandbox 1 this should imply that pushing these changes to Sandbox 2 should also work. 
2. If I add all the components that I changed to the change set, then check for dependencies and add those, that should cover all of the things I need to add to the change set.

Any help appreciated!
Hello!

I've noticed that some managed packages have the ability to auto-populate a lookup field with the current user, before the record is saved for the first time. I want to do this on a custom object we have. For example, if there is a required User lookup field that needs to be filled out, but it's almost always going to be the current user, how could I write a trigger/apex code to auto-populate the lookup with the current user?

I am a complete beginner to Apex code. Thanks in advance for any help!
Hello,

I want to query get the values from the already queried result dynamically
I have below snippet
for (QuoteLineItem q : qli){
                String a = 'Designation__c';
                if(String.isNotBlank(q.Designation__c)){  //Work
                            
                }
				if(String.isNotBlank(q.a)){        //Doest not Work
                            
                }
            }
Can anyone tell me, how could i resolve this issue 

thanks for advise
 
Can someone help me in writing a single query to retrieve old data and new data for the oparticular condition in if satatement?

List Account accs = Trigger.newMap.keySet() ;

 for (Account a : accs)
            if (a.RecordTypeID == '012D00000002qdE' && a.R_seau_int_gr__c == true && a.Etat_relation_GEO__c == 'Déploiement' && (oldmap == null || oldMap.get(a.Id).Etat_relation_GEO__c != 'Déploiement'))
            {
                hasHierarchy = true;
                accIds.add(a.id);
                while (hasHierarchy)
                {
                    List<Account> res = [SELECT id, Etat_relation_GEO__c FROM Account WHERE Etat_relation_GEO__c != 'Terminé' AND parentId IN :accIds];
                    accIds.clear();
                    if (res == null || res.size() == 0)
                        hasHierarchy = false;
                    for (Account aa : res)
                    {
                        accIds.add(aa.id);
                        toUpdate.add(aa);
                    }
                }
            }
 
  • August 16, 2017
  • Like
  • 0
Is there any report or log of some kind - perhaps some way to tell from Logins - which of my users have the Salesforce1 app.
Kind of a noob, sorry fo not knowing the right answer here...does this seem to be on the right track?

IF(ISPICKVAL(Status, "Subscribed"),
           Marketing_Cloud_Subscriber__c.Status__c = False;
           else if (ISPICKVAL(Status, "Unsubscribed"),
           Marketing_Cloud_Subscriber__c.Status__c = True;
One of our templates is referencing a field with {!Opportunity.someid} and I'm not sure what field the id is referring to. How do I search for this field name by the id?
Hello,
I am having difficulty adding a number to a set, then once it is set how do I add 1 to that number?

Code below; I receive error on line 3 of: void add(Decimal) from the type Set<Integer>
and error on line 11 of: void valueOf(Set<Integer>) from the type assign, which is directly related to line 3 not being set
Set<Integer> assignid = new Set<Integer>();
    for(Lead lead : [SELECT AssignIDDateTime__c, Assignment_ID__c FROM Lead WHERE AssignIDDateTime__c != null ORDER BY AssignIDDateTime__c DESC LIMIT 1]){
        assignid.add(lead.Assignment_ID__c);
    }
    
    for(Lead l : Trigger.new){
        if(l.Status == 'Underwriting'){
	        if(l.AssignIDDateTime__c == null){
            	l.Assignment_ID__c = decimal.valueOf(1);
            }else{
                l.Assignment_ID__c = decimal.valueOf(assignid) + decimal.valueOf(1);
            }
        }

    }
Thank you!

Posting this in order to help others who, months from now, might Google "OP_WITH_INVALID_USER_TYPE_EXCEPTION" and find this explanation.

 

We wrote an Apex trigger on the User object, to insert a custom object record anytime a user updates their Chatter status.  This was done to fulfill a client's requirement to audit all Chatter activity.

 

The trigger worked fine, until one day the client signed up some Chatter Free users.  When such a user tried to update their status, they got a pop-up with an OP_WITH_INVALID_USER_TYPE_EXCEPTION error.

 

We scratched our collective heads for awhile.  After all, Apex triggers run in "system mode," right?  That is supposed to mean that "object and field-level permissions of the current user are ignored."  And yet this trigger seemed like it was running in "user mode," enforcing restrictions based on who the current user was.

 

The root cause turned out to be that a Chatter Free user cannot be the owner of a custom object record, and SFDC by default sets the current user as a new record's first owner.  We discovered this when we realized, via experiment, that Apex triggers fired as the result of actions by Chatter Free users could definitely update an existing record, but were having problems creating records.

 

So the simple solution was to explicitly set the owner of the new record to some fully-licensed user prior to inserting it.