• Travis16
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 12
    Replies
So I am trying to write a Visualforce page that will show a related list of Project_Roles__c that are related to it's Parents Object Project__c. I want to show this on the opportunity object which is also a child object of Project__c. I am just not sure if this is possible and how to write the SOQL that will pick up the project ID from the Opportunity. Does this have to be a nested SOQL statement that will lookup the Project information from the Opportunity then the project Role information from the Project? 

Something like 
SELECT ID, Project_Name_2__c,
SELECT Account__c,Appointed__c,Contact__c,Project__c,Role__c FROM Project_Role__c WHERE Project__c = 'Project_Name_2__c'
FROM Opportunity

Then I can put this in a list where I can pull on Visualforce page. Sorry I am not a developer but trying to work my way through this. 
I have a workflow rule that updates the Opportunity name and for some of them they are ending in a special Characters IE. "." due to the Account name ending in Co. or Inc. 

Below is the formula and I need to write it to stop the ending of the name being a special Character. 

IF(OR(ISPICKVAL( Sector__c, "Tate"),ISPICKVAL( Sector__c, "Light + Air")), 
LEFT( 
(Project_Name_2__r.Project_Name_Editable__c 
+ " - " + 
Opportunity_Description__c 
+ " - " + 
Account.H_Account_Name__c), 70) , 


"Q" + "-" + UPPER( Owner.Alias ) + 

LEFT( TEXT( CreatedDate ), 4) + 
RIGHT((LEFT( TEXT( CreatedDate ), 7)), 2) + 
RIGHT((LEFT( TEXT( CreatedDate ), 10)), 2) + "-" + 

RIGHT((LEFT( TEXT( CreatedDate ), 13)), 2) + 

RIGHT((LEFT( TEXT( CreatedDate ), 16)), 2) )
Trying to write a test class for the following trigger that gives access to community members for documents under the quotes object. I am just not sure how to test/check in the test class. 

Trigger
trigger shareFilesWithCommunityUsers on ContentDocumentLink(before insert){

   Schema.DescribeSObjectResult r = Quote.sObjectType.getDescribe();
    String keyPrefix = r.getKeyPrefix();

      for(ContentDocumentLink cdl:trigger.new){
        if((String.valueOf(cdl.LinkedEntityId)).startsWith(keyPrefix)){
          cdl.ShareType = 'I';
          cdl.Visibility = 'AllUsers';
          } 
       }
    }

Test Class
@IsTest
Public class TestShareFilesWithCommunityUsers {
    
     static testmethod void testmethod1(){
        

        
           //Create 2 accounts
        List<Account> accounts = new List<Account>();
        Account accA = bg_Account_Test_Utils.createAccount('Influencer', 'Account A');
        accounts.add(accA);
        insert accounts;

        //Create 2 contacts, linked to the accounts
        List<Contact> contacts = new List<Contact>();
        Contact conA = bg_Contact_Test_Utils.createContact('Test', 'Contact A', accA.Id);
        contacts.add(conA);
        insert contacts;

        //Create a project
        Project__c project = bg_Project_Test_Utils.createProject('Test Project 1', 'Education', 'Tender Phase', 'Leeds', 'LS61QF', accA.Id, conA.Id, 'New build project');
        insert project;

        List<Opportunity> opps = new List<Opportunity>();
        Opportunity wonOpp = bg_Opportunity_Test_Utils.createOpportunity('Controlled Environments', 'Opportunity 1', accA.Id, 'Outline Specification', project.Id, Date.Today() + 30);
        opps.add(wonOpp);
        insert opps;
        
        Quote Q = New Quote(Name='Test Quote', OpportunityId=WonOpp.Id);
        insert Q;
        
        ContentDocumentLink contentlink=new ContentDocumentLink();
        contentlink.LinkedEntityId=q.id;
        contentlink.ShareType= 'I';
        contentlink.LinkedEntityId = q.Id; 
        contentlink.Visibility = 'AllUsers'; 
        insert contentlink;
         
   }
}

Sorry Still Trying to Wrap my head around apex. 
I am not sure what is wrong with the Syntax but I believe I am missing something around the SOQL as I wan't getting this until I changed that. 

trigger OrderUpdateDrafter on Order__c (before insert) {
    String drafterEmail;
    for (Order__c o : Trigger.new){
        //Get all the Drafting records in a list where drafting is on the order
        List<Drafting> myDrafting = new List<Drafting> {
            myDrafting = [SELECT Id,
                          (SELECT Drafter_Email__c,Drafter__c, Order__c
                          FROM Drafting__r 
                          LIMIT 1)
                          FROM Order__c WHERE Id IN : Order__c]
                }
        //check if list is empty if not we will update the order with the Drafters email
        if(myDrafting() > 0 && o.Drafting_Email__c = null) {
            o.Drafter_Email__c == myDrafting.Drafter_Email__c;
        }
    }
}
I am writing a trigger that will Query Child records of a custom object and return 1 value. As there should only be 1 child record we need to pull back the email address of the assigned Drafter. Once we have the Drafters email we will use that in process builder to send out emails when a change is made if it affects the Department. I think there is something wrong with my SOQL as I am getting an error around the expected ; and got o.id. I am not sure what I did wrong. a fresh set of Eyes would help. Thanks 

Trigger (Not Complete)
trigger updateDrafterEmail on Order__c (before insert) {
    String drafterEmail;
    for (Order__c o : Trigger.new){
        //Get all the Drafting records in a list where drafting is on the order
        List<Drafting> myDrafting = new List<Drafting> {
            myDrafting = [SELECT Id, 
                                 SAP_Order__c,
                                 Drafting_Kingspan__c,
                                 Drafting_Email__c, 
                            WHERE Id
                            In 
                            (SELECT Drafter__c, 
                                     Drafter_Email__c 
                             FROM    Drafting__r 
                             WHERE   Drafter__c != null ) 
                             Limit 1;
        }
        //check if list is empty if not we will update the order with the Drafters email
        if(myDrafting > 0 && o.Drafter_Email__c != null){


        }
    }
}
 
So within our community we have a query that finds the logged in users information and we use that to query the orders (custom orders object) on the account to show on our orders page. An issue has been brought up that the contact could be on another accounts and the business wants all the orders to show. 

So here are the options and questions about each option I have. 
User ContactRoles on the accounts to link the single contact to mulitple accounts. 
1. Can I query based off contact roles over all the accounts to pull back orders. (I feel like this might cause issues with the amount of data)

Change the business process and have 1 accounts here all contacts live and there is not duplication. I wouldn't need to change anything here as all the orders will be based on the contacts accounts. (I feel like this is the best option for a cleaner database)
1. Any advice on how to speak to this with higher ups so they understand. 

Use Parent account relationship and change the query so it is based off the master parent account and queries all child accounts to show the orders. 
1. Is there any way to tell if the account is a master account (the highest in the hierarchy)?
2. Would I be able to split these orders up on my visual force page dynamicly based off location of the account? (I have no Idea how this is possible with all the variastions there might be)

Thanks in advance 
 
Trying to write a test class for the following trigger that gives access to community members for documents under the quotes object. I am just not sure how to test/check in the test class. 

Trigger
trigger shareFilesWithCommunityUsers on ContentDocumentLink(before insert){

   Schema.DescribeSObjectResult r = Quote.sObjectType.getDescribe();
    String keyPrefix = r.getKeyPrefix();

      for(ContentDocumentLink cdl:trigger.new){
        if((String.valueOf(cdl.LinkedEntityId)).startsWith(keyPrefix)){
          cdl.ShareType = 'I';
          cdl.Visibility = 'AllUsers';
          } 
       }
    }

Test Class
@IsTest
Public class TestShareFilesWithCommunityUsers {
    
     static testmethod void testmethod1(){
        

        
           //Create 2 accounts
        List<Account> accounts = new List<Account>();
        Account accA = bg_Account_Test_Utils.createAccount('Influencer', 'Account A');
        accounts.add(accA);
        insert accounts;

        //Create 2 contacts, linked to the accounts
        List<Contact> contacts = new List<Contact>();
        Contact conA = bg_Contact_Test_Utils.createContact('Test', 'Contact A', accA.Id);
        contacts.add(conA);
        insert contacts;

        //Create a project
        Project__c project = bg_Project_Test_Utils.createProject('Test Project 1', 'Education', 'Tender Phase', 'Leeds', 'LS61QF', accA.Id, conA.Id, 'New build project');
        insert project;

        List<Opportunity> opps = new List<Opportunity>();
        Opportunity wonOpp = bg_Opportunity_Test_Utils.createOpportunity('Controlled Environments', 'Opportunity 1', accA.Id, 'Outline Specification', project.Id, Date.Today() + 30);
        opps.add(wonOpp);
        insert opps;
        
        Quote Q = New Quote(Name='Test Quote', OpportunityId=WonOpp.Id);
        insert Q;
        
        ContentDocumentLink contentlink=new ContentDocumentLink();
        contentlink.LinkedEntityId=q.id;
        contentlink.ShareType= 'I';
        contentlink.LinkedEntityId = q.Id; 
        contentlink.Visibility = 'AllUsers'; 
        insert contentlink;
         
   }
}

Sorry Still Trying to Wrap my head around apex. 
I am not sure what is wrong with the Syntax but I believe I am missing something around the SOQL as I wan't getting this until I changed that. 

trigger OrderUpdateDrafter on Order__c (before insert) {
    String drafterEmail;
    for (Order__c o : Trigger.new){
        //Get all the Drafting records in a list where drafting is on the order
        List<Drafting> myDrafting = new List<Drafting> {
            myDrafting = [SELECT Id,
                          (SELECT Drafter_Email__c,Drafter__c, Order__c
                          FROM Drafting__r 
                          LIMIT 1)
                          FROM Order__c WHERE Id IN : Order__c]
                }
        //check if list is empty if not we will update the order with the Drafters email
        if(myDrafting() > 0 && o.Drafting_Email__c = null) {
            o.Drafter_Email__c == myDrafting.Drafter_Email__c;
        }
    }
}
I am writing a trigger that will Query Child records of a custom object and return 1 value. As there should only be 1 child record we need to pull back the email address of the assigned Drafter. Once we have the Drafters email we will use that in process builder to send out emails when a change is made if it affects the Department. I think there is something wrong with my SOQL as I am getting an error around the expected ; and got o.id. I am not sure what I did wrong. a fresh set of Eyes would help. Thanks 

Trigger (Not Complete)
trigger updateDrafterEmail on Order__c (before insert) {
    String drafterEmail;
    for (Order__c o : Trigger.new){
        //Get all the Drafting records in a list where drafting is on the order
        List<Drafting> myDrafting = new List<Drafting> {
            myDrafting = [SELECT Id, 
                                 SAP_Order__c,
                                 Drafting_Kingspan__c,
                                 Drafting_Email__c, 
                            WHERE Id
                            In 
                            (SELECT Drafter__c, 
                                     Drafter_Email__c 
                             FROM    Drafting__r 
                             WHERE   Drafter__c != null ) 
                             Limit 1;
        }
        //check if list is empty if not we will update the order with the Drafters email
        if(myDrafting > 0 && o.Drafter_Email__c != null){


        }
    }
}