• Palmira Angelova
  • NEWBIE
  • 50 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 14
    Replies
Hi friends,

I need to look up specific Contacts on Accounts, but only include Contacts on Accounts that have Opportunities WHERE Stage IN('X','Y','Z') i.e. what I think of as a child -> parent -> child lookup. I've been using workbench for this. 

I couldn't figure out a way to do this within the syntax, so instead I opted for Account -> Contacts WHERE Account -> Opportunities meets my criteria, which seemed to make sense to me. However, my query is getting an error telling me I can't have a child -> parent lookup in the where clause:
"MALFORMED_QUERY: 
AND Id IN(SELECT Account.Id FROM Opportunity WHERE
ERROR at Row:5:Column:24
The inner select field 'Account.Id' cannot have more than one level of relationships"

Here is my query:
SELECT Id,
       (SELECT Id FROM Contacts WHERE Send_Partner_Updates__c = TRUE)
FROM Account
WHERE Account.POS_Provider_s__c NOT IN('Toshiba ACE', 'Toshiba ACE (old, non-integrated)')
      AND Id IN(SELECT Account.Id FROM Opportunity WHERE Stage IN('6 - Deployed', '6 - Deploying', '6.5 - Fully Deployed'))

Does anyone have a way to get by this? When I tried "SELECT Id FROM Opportunity", removing the child->parent lookup within the Opportunity query, I get this error: "The selected field 'Id' in the subquery and the left operand field in the where expression in the outer query 'Id' should point to the same object type"...so I haven't been able to think of a way around these two limitations.

Thanks for your help!
Hi friends,

I feel kind of silly posting this, but here goes. In our org, Orders are created on Opportunities and have a start and end date. Orders must also be associated with Contracts, which also have a start and end date. Pretty standard stuff. 

Recently, Date = Today surpassed the Contract End Date for one of our contracts (this is ok and was designed this way - the continuation of the contract is actually recorded in a new "renewal" Opportunity that is tied to the originating Opportunity and the original Contract. We're attempting to create an order on the associated (renewal) Opportunity but getting the following error: "Malformed request https://na34.salesforce.com/services/data/v38.0/sobjects/Order/. Response content: [{'fields': ['EffectiveDate'], 'message': "Order Start Date can't be later than its contract's end date.: Order Start Date", 'errorCode': 'FIELD_INTEGRITY_EXCEPTION'"

This totally looks like a custom validation or error message to me (but please correct me if I'm wrong?? Maybe there's a chance Salesforce built in validation rules for these Standard Salesforce fields and that's what I'm missing here?), but the weird thing is that I can't find mention of the "Order Start Date can't be later than its contract's end date" error ANYWHERE in the org. I've combed through every line of code and validation rule like 3 times and it's nowhere to be found. Is there some other obscure way to create data validation that I'm not aware of? 

Or any other ideas that could point me in the right direction? I need to find the culprit and disable / modify this rule. Thanks so much!

Hi friends,

I'm an admin just branching into apex development - so many of the examples I'm seeing around the forums have colored code, which makes it easier / faster to read. How do you actiate this? At the moment, all of my Salesforce code color is black (or maybe faintly colored but very dark), but I've seen many colored examples around like this one: https://www.dropbox.com/s/5krau2vfq9b2dru/Screenshot%202017-12-11%2013.16.17.jpg?dl=0

I can't find info anywhere online on how to change the coloring of the code while editing! If you could point me in the right direction I'd be really grateful!
Thanks,

Palmira

Hi friends,

I'm an experienced admin but still very new to development. 

I'm trying to push some code that will mandate that a Contact Role be select before an Opportunity can be edited (this is necessary for an integration I'm working on with Hubspot). However, I'm running into the below error in my test case and can't figure out what I'm doing wrong - I've read about this on other forums, but selecting a price book is not like creating an object like an oppty or product in my eyes, so not sure how this applies:
"System.QueryException: List has no rows for assignment to SObject 
Stack Trace: Class.NumberofContactRoles_Test.TestCase1: line 26, column 1" (this is the PriceBook2 line below)

Could someone help me tweak the test case to avoid this error? Thank you sincerely for your help!

@isTest
public class NumberofContactRoles_Test{

    public static testmethod void TestCase1()
    {
    
    Contact ConTest = new Contact();
    ConTest.FirstName = 'TEstCon';
    ConTest.LastName = 'LastName';
    
    insert ConTest;
    System.assertNotEquals(null,ConTest.Id);
    
    Opportunity Opp1 = new Opportunity();
    
    Opp1.Name = 'TestOpp';
    Opp1.StageName = 'Prospect';
    Opp1.CloseDate = System.today()+10;
    
    insert Opp1;
    System.assertNotEquals(null,Opp1.Id);

    Product2 pd = new Product2(Name='Additional Processor Routing2',isActive=true, Family='PR', ProductCode='Payments & Security');
    insert pd;

    PriceBook2 pb2Standard = [select Id from Pricebook2 where isStandard=true limit 1];
    Id standardPriceBookId = pb2Standard.Id;

    PricebookEntry pbe = new PricebookEntry(Pricebook2Id=standardPriceBookId, Product2Id=pd.Id, UnitPrice=99, isActive=true);
    insert pbe;
    
    OpportunityLineItem Oli1 = new OpportunityLineItem();
    Oli1.OpportunityId = opp1.Id;
    Oli1.PricebookEntryId = [select Id from PricebookEntry where isactive=true AND product2.Name='Additional Processor Routing' and Pricebook2.Isstandard=True limit 1][0].id;
    Oli1.UnitPrice = 50;
    Oli1.Quantity=10;
    insert Oli1;
    
    OpportunityContactRole oppRole = new OpportunityContactRole();
    oppRole.OpportunityId = Opp1.Id;
    oppRole.IsPrimary = True;
    oppRole.ContactId = ConTest.Id;
    
    insert oppRole;
    System.assertNotEquals(null,OppRole.Id);
    
    Opp1.Name = 'TestOpp2';
    update Opp1;
    }
}
Hi everyone,

I'm an experienced admin, but am very new to development (just learning random bits here and there, as I don't have enough time in my job to do this the proper way.) I'm trying to deploy the code below but am not able to write a test that the Salesforce org will accept as >0%. I have tested all the functionality I need and am confident this won't break anything.

If someone could help create some very simple test coverage so I can push this to production, I'd be incredibly grateful. Thank you!

New Opportunity Trigger: 

trigger NumberofContactRoles on Opportunity (before update, after undelete) 

{
Set<Id> opportunityIds = Trigger.newMap.keySet();
List<OpportunityContactRole> contactRoles = [
        SELECT OpportunityId, IsPrimary
        FROM OpportunityContactRole
        WHERE OpportunityId IN :opportunityIds
];

Set<Id> opportunitiesWithContactIds = new Set<Id>();
Map<Id, Integer> contactRoleCount = new Map<Id, Integer>();

for (OpportunityContactRole contactRole: contactRoles) {
    if (contactRole.IsPrimary == True) {
        opportunitiesWithContactIds.add(contactRole.OpportunityId);
    }
    if (contactRoleCount.containsKey(contactRole.OpportunityId)) {
        contactRoleCount.put(contactRole.OpportunityId,
                contactRoleCount.get(contactRole.OpportunityId) + 1
        );
    } else {
        contactRoleCount.put(contactRole.OpportunityId, 1);
    }
}

for (Opportunity oppty : system.trigger.new) {
    if (contactRoleCount.containsKey(oppty.Id)) {
        oppty.Number_of_Contact_Roles_Assigned__c = contactRoleCount.get(oppty.Id);   
    } else {
        oppty.Number_of_Contact_Roles_Assigned__c = 0;
    }
}
}
Hi friends,

I need to look up specific Contacts on Accounts, but only include Contacts on Accounts that have Opportunities WHERE Stage IN('X','Y','Z') i.e. what I think of as a child -> parent -> child lookup. I've been using workbench for this. 

I couldn't figure out a way to do this within the syntax, so instead I opted for Account -> Contacts WHERE Account -> Opportunities meets my criteria, which seemed to make sense to me. However, my query is getting an error telling me I can't have a child -> parent lookup in the where clause:
"MALFORMED_QUERY: 
AND Id IN(SELECT Account.Id FROM Opportunity WHERE
ERROR at Row:5:Column:24
The inner select field 'Account.Id' cannot have more than one level of relationships"

Here is my query:
SELECT Id,
       (SELECT Id FROM Contacts WHERE Send_Partner_Updates__c = TRUE)
FROM Account
WHERE Account.POS_Provider_s__c NOT IN('Toshiba ACE', 'Toshiba ACE (old, non-integrated)')
      AND Id IN(SELECT Account.Id FROM Opportunity WHERE Stage IN('6 - Deployed', '6 - Deploying', '6.5 - Fully Deployed'))

Does anyone have a way to get by this? When I tried "SELECT Id FROM Opportunity", removing the child->parent lookup within the Opportunity query, I get this error: "The selected field 'Id' in the subquery and the left operand field in the where expression in the outer query 'Id' should point to the same object type"...so I haven't been able to think of a way around these two limitations.

Thanks for your help!
Hi friends,

I need to look up specific Contacts on Accounts, but only include Contacts on Accounts that have Opportunities WHERE Stage IN('X','Y','Z') i.e. what I think of as a child -> parent -> child lookup. I've been using workbench for this. 

I couldn't figure out a way to do this within the syntax, so instead I opted for Account -> Contacts WHERE Account -> Opportunities meets my criteria, which seemed to make sense to me. However, my query is getting an error telling me I can't have a child -> parent lookup in the where clause:
"MALFORMED_QUERY: 
AND Id IN(SELECT Account.Id FROM Opportunity WHERE
ERROR at Row:5:Column:24
The inner select field 'Account.Id' cannot have more than one level of relationships"

Here is my query:
SELECT Id,
       (SELECT Id FROM Contacts WHERE Send_Partner_Updates__c = TRUE)
FROM Account
WHERE Account.POS_Provider_s__c NOT IN('Toshiba ACE', 'Toshiba ACE (old, non-integrated)')
      AND Id IN(SELECT Account.Id FROM Opportunity WHERE Stage IN('6 - Deployed', '6 - Deploying', '6.5 - Fully Deployed'))

Does anyone have a way to get by this? When I tried "SELECT Id FROM Opportunity", removing the child->parent lookup within the Opportunity query, I get this error: "The selected field 'Id' in the subquery and the left operand field in the where expression in the outer query 'Id' should point to the same object type"...so I haven't been able to think of a way around these two limitations.

Thanks for your help!
Hi friends,

I feel kind of silly posting this, but here goes. In our org, Orders are created on Opportunities and have a start and end date. Orders must also be associated with Contracts, which also have a start and end date. Pretty standard stuff. 

Recently, Date = Today surpassed the Contract End Date for one of our contracts (this is ok and was designed this way - the continuation of the contract is actually recorded in a new "renewal" Opportunity that is tied to the originating Opportunity and the original Contract. We're attempting to create an order on the associated (renewal) Opportunity but getting the following error: "Malformed request https://na34.salesforce.com/services/data/v38.0/sobjects/Order/. Response content: [{'fields': ['EffectiveDate'], 'message': "Order Start Date can't be later than its contract's end date.: Order Start Date", 'errorCode': 'FIELD_INTEGRITY_EXCEPTION'"

This totally looks like a custom validation or error message to me (but please correct me if I'm wrong?? Maybe there's a chance Salesforce built in validation rules for these Standard Salesforce fields and that's what I'm missing here?), but the weird thing is that I can't find mention of the "Order Start Date can't be later than its contract's end date" error ANYWHERE in the org. I've combed through every line of code and validation rule like 3 times and it's nowhere to be found. Is there some other obscure way to create data validation that I'm not aware of? 

Or any other ideas that could point me in the right direction? I need to find the culprit and disable / modify this rule. Thanks so much!

Hi friends,

I'm an admin just branching into apex development - so many of the examples I'm seeing around the forums have colored code, which makes it easier / faster to read. How do you actiate this? At the moment, all of my Salesforce code color is black (or maybe faintly colored but very dark), but I've seen many colored examples around like this one: https://www.dropbox.com/s/5krau2vfq9b2dru/Screenshot%202017-12-11%2013.16.17.jpg?dl=0

I can't find info anywhere online on how to change the coloring of the code while editing! If you could point me in the right direction I'd be really grateful!
Thanks,

Palmira

Hi friends,

I'm an experienced admin but still very new to development. 

I'm trying to push some code that will mandate that a Contact Role be select before an Opportunity can be edited (this is necessary for an integration I'm working on with Hubspot). However, I'm running into the below error in my test case and can't figure out what I'm doing wrong - I've read about this on other forums, but selecting a price book is not like creating an object like an oppty or product in my eyes, so not sure how this applies:
"System.QueryException: List has no rows for assignment to SObject 
Stack Trace: Class.NumberofContactRoles_Test.TestCase1: line 26, column 1" (this is the PriceBook2 line below)

Could someone help me tweak the test case to avoid this error? Thank you sincerely for your help!

@isTest
public class NumberofContactRoles_Test{

    public static testmethod void TestCase1()
    {
    
    Contact ConTest = new Contact();
    ConTest.FirstName = 'TEstCon';
    ConTest.LastName = 'LastName';
    
    insert ConTest;
    System.assertNotEquals(null,ConTest.Id);
    
    Opportunity Opp1 = new Opportunity();
    
    Opp1.Name = 'TestOpp';
    Opp1.StageName = 'Prospect';
    Opp1.CloseDate = System.today()+10;
    
    insert Opp1;
    System.assertNotEquals(null,Opp1.Id);

    Product2 pd = new Product2(Name='Additional Processor Routing2',isActive=true, Family='PR', ProductCode='Payments & Security');
    insert pd;

    PriceBook2 pb2Standard = [select Id from Pricebook2 where isStandard=true limit 1];
    Id standardPriceBookId = pb2Standard.Id;

    PricebookEntry pbe = new PricebookEntry(Pricebook2Id=standardPriceBookId, Product2Id=pd.Id, UnitPrice=99, isActive=true);
    insert pbe;
    
    OpportunityLineItem Oli1 = new OpportunityLineItem();
    Oli1.OpportunityId = opp1.Id;
    Oli1.PricebookEntryId = [select Id from PricebookEntry where isactive=true AND product2.Name='Additional Processor Routing' and Pricebook2.Isstandard=True limit 1][0].id;
    Oli1.UnitPrice = 50;
    Oli1.Quantity=10;
    insert Oli1;
    
    OpportunityContactRole oppRole = new OpportunityContactRole();
    oppRole.OpportunityId = Opp1.Id;
    oppRole.IsPrimary = True;
    oppRole.ContactId = ConTest.Id;
    
    insert oppRole;
    System.assertNotEquals(null,OppRole.Id);
    
    Opp1.Name = 'TestOpp2';
    update Opp1;
    }
}
Hi everyone,

I'm an experienced admin, but am very new to development (just learning random bits here and there, as I don't have enough time in my job to do this the proper way.) I'm trying to deploy the code below but am not able to write a test that the Salesforce org will accept as >0%. I have tested all the functionality I need and am confident this won't break anything.

If someone could help create some very simple test coverage so I can push this to production, I'd be incredibly grateful. Thank you!

New Opportunity Trigger: 

trigger NumberofContactRoles on Opportunity (before update, after undelete) 

{
Set<Id> opportunityIds = Trigger.newMap.keySet();
List<OpportunityContactRole> contactRoles = [
        SELECT OpportunityId, IsPrimary
        FROM OpportunityContactRole
        WHERE OpportunityId IN :opportunityIds
];

Set<Id> opportunitiesWithContactIds = new Set<Id>();
Map<Id, Integer> contactRoleCount = new Map<Id, Integer>();

for (OpportunityContactRole contactRole: contactRoles) {
    if (contactRole.IsPrimary == True) {
        opportunitiesWithContactIds.add(contactRole.OpportunityId);
    }
    if (contactRoleCount.containsKey(contactRole.OpportunityId)) {
        contactRoleCount.put(contactRole.OpportunityId,
                contactRoleCount.get(contactRole.OpportunityId) + 1
        );
    } else {
        contactRoleCount.put(contactRole.OpportunityId, 1);
    }
}

for (Opportunity oppty : system.trigger.new) {
    if (contactRoleCount.containsKey(oppty.Id)) {
        oppty.Number_of_Contact_Roles_Assigned__c = contactRoleCount.get(oppty.Id);   
    } else {
        oppty.Number_of_Contact_Roles_Assigned__c = 0;
    }
}
}
I'm using a visual flow to create an Order and Contract (if one doesn't exist) from an accepted Quote. I'm getting a field integrity error saying that the Order End Date can't be later than the Contract End Date but they are the same. 

Here are shots of the error email I get indicating that the Contract End Date is being used to set the Order End Date. The value that gets entered in this case is July 1, 2019 which then gets transformed to June 30, 2019 8:00 PM which I assume is because I'm in Eastern time (though not sure why it's tranforming a date to a datetime as this is a date field). In both cases though the date (datetime) is exactly the same so I can't see why it would throw the error.

Contract end date

Order end date
I get this error: Challenge Not yet complete... here's what's wrong: 
The Suggestion custom object does not contain the correct set of custom fields. Tip: check for typos in the field names.

I've followed all steps, went back and rechecked, and then redid the entire challenge. I can't get it to pass. What am I doing wrong? I have included all custom fields and spelled them correctly.