• Nathan Prats 22
  • NEWBIE
  • 50 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 10
    Replies
Hello, 

Since 2 days, I can't launch Eclipse. 
I receive this error message.



User-added image
Here's the log..

I don't get it. 

User-added image

Any Idea ? 

Nathan
 
Hi, 

I receive this error on a test class. 
It's due to this piece of code : "Database.update(opty)", but I don't get why. Any idea ? 
System.DmlException: Update failed. First exception on row 0 with id 0068E00000EEPmvQAH; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityTriggers: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.OpportunityTriggers: line 24, column 1: []

My Test Class
 
@isTest
private class OpportunityTriggersTest {
    private static String name='Test Account';
    
    /// Nathan Prats 06/22/2018.
    @isTest static void PrimaryPartnerGrossMarginTest() {
        
        // Create accounts & contact & opportunity & opportunity contact role
        Account acct = TestUtils.CreateAccount('Standard'+ name);
        Account pacct = TestUtils.CreatePartnerAccount(' partner'+ name);
        Contact con  = TestUtils.CreateContact('firstName','lastName',acct);
        Opportunity opty = TestUtils.CreateOpportunity(acct, pacct);
        OpportunityContactRole ocr = TestUtils.CreateContactRoleOnOpportunity(con, opty);
        
        // Set partner information
        opty.Primary_Partner_Role__c='Reseller';
        opty.Primary_Partner_Margin__c=20;
        opty.RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('SaaS Enterprise').getRecordTypeId();
        
        // Create a quote and sync it
        Quote qte = TestUtils.CreateQuote(con,opty);
        opty.SyncedQuoteId = qte.Id;
        Database.update(opty);
        
        // Create 2 products, a software product and a non software product
        Product2 pdct1= TestUtils.CreateProduct2('Product1','Software');
        Product2 pdct2= TestUtils.CreateProduct2('Product2','Customer Success');
        
        // Create 2 PriceBookEntries
        PricebookEntry pbe1 = TestUtils.createPricebookEntry(pdct1,100);
        PricebookEntry pbe2 = TestUtils.createPricebookEntry(pdct2,200);
        
        // Add 2 Quote Line Items, a software product and a non software product
        QuoteLineItem qli1 = TestUtils.createQuoteLineItem(pdct1,qte,1,Date.today(),100,pbe1);
        QuoteLineItem qli2 = TestUtils.createQuoteLineItem(pdct2,qte,1,Date.today(),200,pbe2);
        
        // Verify that the Primary_Partner_Gross_Margin__c = sum of software opportunity products * % margin
        // Should be 20 in this case, not 20+40.
        System.assertEquals(20, opty.Primary_Partner_Gross_Margin__c);
        
    }
}

 
Hi, 

I'm trying to update a field named Primary Partner Gross Margin on the opportunity object based on opportunity line items. 
The code compiles, but it doesn't update the field on update. Any idea why ? 
trigger OpportunityTriggers on Opportunity (before update) {
    
    // Quand 1 Opp a un Primary Partner Account Reseller, remplir le champs "Primary Partner Gross Margin" = Sum OpportunityLineItems Software  * Primary_Partner_Margin__c
    // C'est forcément before car on a besoin d'update des records, et quand on est en after, les records sont lock
    
    // Prendre la liste des opportunités pour lesquelles on va peupler Primary_Partner_Gross_Margin__c
    For (Opportunity opp : [SELECT Id,Primary_Partner_Gross_Margin__c,Primary_Partner_Margin__c 
                            FROM Opportunity
                            WHERE Primary_Partner_Role__c ='Reseller'
                            AND Deal_with_a_partner__c = 'Yes'
                            AND Id IN :Trigger.old
                           ]) {
                               
                               // Updater le champs Primary_Partner_Gross_Margin__c
                               Double GrossMargin = [SELECT TotalPrice 
                                                      FROM OpportunityLineItem
                                                      WHERE PricebookEntry.product2.Family='Software'
                                                      AND  OpportunityId =: opp.Id ][0].TotalPrice;
                               
                               
                               opp.Primary_Partner_Gross_Margin__c=GrossMargin*opp.Primary_Partner_Margin__c;
                               opp.Name = 'Worked';
                               
                           }
}

 
Hi, 

I have this error when working on a dataflow : Something went wrong while executing the Extract_OpportunityHistory node: Field CloseDate referred in schema for node Extract_OpportunityHistory but is not present in result edgemart (02K2X000000Xo0MUAS_03C2X000000Y2LOUA0)

How can I analyse this part ? 02K2X000000Xo0MUAS_03C2X000000Y2LOUA0

thanks, 
Hi, 

I'd like to use the Summer 18 functionality : nested report folders. 
I wanna move some reports to a new report folder I created : "Obsolete Report Folders" via Eclipse. 

I tried to drag & drop report folders, move metadata, etc... but it doesn't work. 

Any Idea ? 
Hello, 

I created this trigger which set a share type for each new content document link. 
trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert) {
    
    for(ContentDocumentLink cdl: Trigger.new){
        cdl.shareType = 'I';
    } 
}
I tried to create this test class:
@isTest
public class ContentDocumentLinkTriggerTest {
    
    @isTest static void ContentDocumentLinkTriggerTest() {
        
        // Create a ContentVersion
        ContentVersion ContentDoc = new ContentVersion();
        ContentDoc.Title = 'My Doc';
        ContentDoc.ContentUrl= 'test.com';
        Insert ContentDoc;
        
        // Create a ContentDocumentLink
        ContentDocumentLink ContentDL = new ContentDocumentLink();
        ContentDL.ContentDocumentId = ContentDoc.Id;
        Insert ContentDL;
        
        // Verify the share type is = i
        System.assertEquals(ContentDL.ShareType,'I');
        
        
    }
}

But I receive this error: 
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, ContentDocument ID: id value of incorrect type: 0683E0000003EXVQA2: [ContentDocumentId]

Any idea why ? 
Hello, 

I'm trying to force our sales reps to fill a primary contact on opportunities before they change the opportunity to the stage "Won by Sales". 
I created this trigger on opportunity but it doesn't work.
 
I receive this error : You encountered some errors when trying to save this record
There's a problem saving this record. You might not have permission to edit it, or it might have been deleted or archived. Contact your administrator for help.


I think I need some kind of map but I can't figure it out. Any idea ? 
 
trigger OpportunityTriggers on Opportunity (before delete, before insert, before update,after delete, after insert, after update) {
    
    if (Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate)) {
        
        For (Opportunity o : [SELECT Id,
                              (select ContactId from OpportunityContactRoles where IsPrimary=true LIMIT 1)
                              FROM Opportunity
                              WHERE StageName='Won by Sales']
            ) 
        {
            
            if (o.OpportunityContactRoles.size() != 1){
                o.addError(System.Label.Missing_Primary_Contact);                                     
            }
        }
    }
}
Nathan
 
Hello, 

I have this code :
 
List<Account> AccList = [SELECT Id,OwnerId,Parent.OwnerId 
                         FROM Account 
                         WHERE Account_Owner_Parent_Owner__c = TRUE 
                         AND IsExcludedFromRealign = FALSE];

Integer X = [SELECT Count()
             FROM Account 
             WHERE Account_Owner_Parent_Owner__c = TRUE 
             AND IsExcludedFromRealign = FALSE];

do {
    for(Account Acc : AccList){ 
        Acc.OwnerId = Acc.Parent.OwnerId;
    }
        
        } while (X > 0);

update AccList;

but each time i run it, i have a Limit Usage for NS error. 

10:45:16:000 LIMIT_USAGE_FOR_NS   Maximum CPU time: 15118 out of 10000 ******* CLOSE TO LIMIT

What can be wrong ? 
Hello, 

I created this piece of code that reassigns all accounts to the right owner based on the account hierarchy. 
The issue is that this code reassigns 1 node at a time. 

I'd like it to do this until the following query returns 0 :
[SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE]

Current code
global class ReassignAccounts implements Schedulable {
    
    global void execute(SchedulableContext ctx) {
        List<Account> AccList = [SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE];
        
        for(Account Acc : AccList){    
            Acc.OwnerId = Acc.Parent.OwnerId ;
        }
        
        update AccList; }
    
}
Can I add a while [SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE] > 0, do ... ? 

Thanks, 

Nathan
 
Hello, 

I created this piece of code that reassigns all accounts to the right owner based on the account hierarchy. 
The issue is that this code reassigns 1 node at a time. 

I'd like it to do this until the following query returns 0 : 
SELECT Id,OwnerId,Parent.OwnerId 
FROM Account 
WHERE Account_Owner_Parent_Owner__c = TRUE 
AND IsExcludedFromRealign = FALSE
Current Code
global class ReassignAccounts implements Schedulable {
    
    global void execute(SchedulableContext ctx) {
        List<Account> AccList = [SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE];
        
        for(Account Acc : AccList){    
            Acc.OwnerId = Acc.Parent.OwnerId ;
        }
        
        update AccList; }
    
}

Can I add a while [SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE] > 0, do ... ? 

Thanks, 

Nathan
 
Hi, 

I have this code that doesn't work. I'm trying to convert it as a map as I read in the best practices that I should use maps. 
The custom field Contact_Owner_Account_Owner__c  returns TRUE when the ownerId is different from the account ownerId. 
List<Contact> ContList = [SELECT Id,OwnerId,Account.OwnerId,Contact_Owner_Account_Owner__c 

             FROM Contact 

             WHERE Contact_Owner_Account_Owner__c = TRUE

             AND AccountId != ''];



for(Contact Cont : ContList){   

  Cont.OwnerId = Cont.Account.OwnerId ;

}



update ContList;
Thanks for your help, 

Nathan
 
Hi, 

I'd like to force Single Sign all for all profiles except System Administrators. 
Is it possible ? I don't want to force SSO yet because I'm afraid admin won't be able to log in once I forced it. 

I reached salesforce support but they don't handle SSO request for standard support customers. 

Nathan
Hi !

I created a Schedulable Apex Class to reassign opportunities to the account owner every morning at 6 AM. 
global class ReassignOpps implements Schedulable {
    
    global void execute(SchedulableContext ctx) {
        List<Opportunity> OppList = [SELECT Id,OwnerId,Account.OwnerId 
                                     FROM Opportunity 
                                     WHERE Opportunity_Owner_Account_Owner__c = TRUE 
                                     AND IsClosed = FALSE 
                                     AND IsExcludedFromTerritory2Filter = FALSE];
        
        for(Opportunity Opp : OppList){    
            Opp.OwnerId = Opp.Account.OwnerId ;
        }
        
        update OppList;
    }
    
}
I'm fairly new to Apex, but I think I need to create a Test Class for this Class. 

I started to code this Test Class but I'm stuck. I have no idea what to do from here. 
@isTest
private class ReassignOppsTest {
    
    //Create 2 users
    User u1 = TestUtils.CreateAdminUser('user1');
    User u2 = TestUtils.CreateAdminUser('user2');
    
    //Create an account owned by X and an opportunity owned by Y
    Account acct    = TestUtils.CreateAccount('name');
    Account pacct   = TestUtils.CreatePartnerAccount('Partner name'+' partner');
    Contact con     = TestUtils.CreateContact('firstName','lastName',acct);
    Opportunity opp = TestUtils.CreateOpportunity(acct, pacct, con,'CA');
    
    acct.OwnerId = u1.Id;
    opp.OwnerID = u2.Id;
    
    //Call ReassignOpp Class???
    
    
    // test
    
    
}
I know that I need to create 2 users, 1 Account and 1 Opportunity, then launch the class somehow and then see if the opportunity has been reassign correctly. 

Any help would be more than welcome. 

Nathan
 
Hi, 

My need is quite simple. I need to create a button on the Quote object to send an email with the last attachment attached. 
I already created the button: 

/_ui/core/email/author/EmailAuthor?
p2_lkid=0032X000023Oapf&
rtype=003
&p3_lkid={!QuoteId}&
doc_id=AttachmentId&
&retURL=%2F0{!QuoteId}


I need to Push the AttachmentId To ParentId Custom Field after the Attachement is inserted with a Trigger. 
trigger PushAttachmentIdToParentIdCustomField on Attachment (After Insert) {
    
    

}
Only problem is... I have no idea where to start. 
Any help is more than welcome as I'm fairly new to Apex Development.

Nathan
 
Hi, 

We have 2 Account Record Types, Standard & Partner. I'm trying to create a simple Apex Trigger to prevent a sales rep to change the account record type from Standard to Partner if the account has related opportunities. 

I wrote this, but as I'm new to Apex I'm pretty sure it's plenty wrong. 

trigger PreventEnablePartner on Account (before update) {

For (Account acc : [SELECT Id,RecordTypeId
                    FROM Account
                    WHERE Id IN (SELECT AccountId FROM Opportunity)
                    AND RecordType.Name = 'Partner']) {
                        
Account oldAccount = Trigger.oldMap.get(acc.ID);

IF(acc.RecordTypeId != oldAccount.RecordTypeId ) {
    Trigger.New[0].addError('Cannot "Enable As Partner" an account with related opportunities.');}
    Else {Return;}
}
}

Do you have any idea ? 

Thanks,
Hi, 

I'm trying to update a field named Primary Partner Gross Margin on the opportunity object based on opportunity line items. 
The code compiles, but it doesn't update the field on update. Any idea why ? 
trigger OpportunityTriggers on Opportunity (before update) {
    
    // Quand 1 Opp a un Primary Partner Account Reseller, remplir le champs "Primary Partner Gross Margin" = Sum OpportunityLineItems Software  * Primary_Partner_Margin__c
    // C'est forcément before car on a besoin d'update des records, et quand on est en after, les records sont lock
    
    // Prendre la liste des opportunités pour lesquelles on va peupler Primary_Partner_Gross_Margin__c
    For (Opportunity opp : [SELECT Id,Primary_Partner_Gross_Margin__c,Primary_Partner_Margin__c 
                            FROM Opportunity
                            WHERE Primary_Partner_Role__c ='Reseller'
                            AND Deal_with_a_partner__c = 'Yes'
                            AND Id IN :Trigger.old
                           ]) {
                               
                               // Updater le champs Primary_Partner_Gross_Margin__c
                               Double GrossMargin = [SELECT TotalPrice 
                                                      FROM OpportunityLineItem
                                                      WHERE PricebookEntry.product2.Family='Software'
                                                      AND  OpportunityId =: opp.Id ][0].TotalPrice;
                               
                               
                               opp.Primary_Partner_Gross_Margin__c=GrossMargin*opp.Primary_Partner_Margin__c;
                               opp.Name = 'Worked';
                               
                           }
}

 
Hello, 

I created this trigger which set a share type for each new content document link. 
trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert) {
    
    for(ContentDocumentLink cdl: Trigger.new){
        cdl.shareType = 'I';
    } 
}
I tried to create this test class:
@isTest
public class ContentDocumentLinkTriggerTest {
    
    @isTest static void ContentDocumentLinkTriggerTest() {
        
        // Create a ContentVersion
        ContentVersion ContentDoc = new ContentVersion();
        ContentDoc.Title = 'My Doc';
        ContentDoc.ContentUrl= 'test.com';
        Insert ContentDoc;
        
        // Create a ContentDocumentLink
        ContentDocumentLink ContentDL = new ContentDocumentLink();
        ContentDL.ContentDocumentId = ContentDoc.Id;
        Insert ContentDL;
        
        // Verify the share type is = i
        System.assertEquals(ContentDL.ShareType,'I');
        
        
    }
}

But I receive this error: 
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, ContentDocument ID: id value of incorrect type: 0683E0000003EXVQA2: [ContentDocumentId]

Any idea why ? 
Hello, 

I have this code :
 
List<Account> AccList = [SELECT Id,OwnerId,Parent.OwnerId 
                         FROM Account 
                         WHERE Account_Owner_Parent_Owner__c = TRUE 
                         AND IsExcludedFromRealign = FALSE];

Integer X = [SELECT Count()
             FROM Account 
             WHERE Account_Owner_Parent_Owner__c = TRUE 
             AND IsExcludedFromRealign = FALSE];

do {
    for(Account Acc : AccList){ 
        Acc.OwnerId = Acc.Parent.OwnerId;
    }
        
        } while (X > 0);

update AccList;

but each time i run it, i have a Limit Usage for NS error. 

10:45:16:000 LIMIT_USAGE_FOR_NS   Maximum CPU time: 15118 out of 10000 ******* CLOSE TO LIMIT

What can be wrong ? 
Hello, 

I created this piece of code that reassigns all accounts to the right owner based on the account hierarchy. 
The issue is that this code reassigns 1 node at a time. 

I'd like it to do this until the following query returns 0 :
[SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE]

Current code
global class ReassignAccounts implements Schedulable {
    
    global void execute(SchedulableContext ctx) {
        List<Account> AccList = [SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE];
        
        for(Account Acc : AccList){    
            Acc.OwnerId = Acc.Parent.OwnerId ;
        }
        
        update AccList; }
    
}
Can I add a while [SELECT Id,OwnerId,Parent.OwnerId FROM Account WHERE Account_Owner_Parent_Owner__c = TRUE AND IsExcludedFromRealign = FALSE] > 0, do ... ? 

Thanks, 

Nathan
 
Hi, 

I have this code that doesn't work. I'm trying to convert it as a map as I read in the best practices that I should use maps. 
The custom field Contact_Owner_Account_Owner__c  returns TRUE when the ownerId is different from the account ownerId. 
List<Contact> ContList = [SELECT Id,OwnerId,Account.OwnerId,Contact_Owner_Account_Owner__c 

             FROM Contact 

             WHERE Contact_Owner_Account_Owner__c = TRUE

             AND AccountId != ''];



for(Contact Cont : ContList){   

  Cont.OwnerId = Cont.Account.OwnerId ;

}



update ContList;
Thanks for your help, 

Nathan
 
Hi, 

My need is quite simple. I need to create a button on the Quote object to send an email with the last attachment attached. 
I already created the button: 

/_ui/core/email/author/EmailAuthor?
p2_lkid=0032X000023Oapf&
rtype=003
&p3_lkid={!QuoteId}&
doc_id=AttachmentId&
&retURL=%2F0{!QuoteId}


I need to Push the AttachmentId To ParentId Custom Field after the Attachement is inserted with a Trigger. 
trigger PushAttachmentIdToParentIdCustomField on Attachment (After Insert) {
    
    

}
Only problem is... I have no idea where to start. 
Any help is more than welcome as I'm fairly new to Apex Development.

Nathan
 
Hi, 

We have 2 Account Record Types, Standard & Partner. I'm trying to create a simple Apex Trigger to prevent a sales rep to change the account record type from Standard to Partner if the account has related opportunities. 

I wrote this, but as I'm new to Apex I'm pretty sure it's plenty wrong. 

trigger PreventEnablePartner on Account (before update) {

For (Account acc : [SELECT Id,RecordTypeId
                    FROM Account
                    WHERE Id IN (SELECT AccountId FROM Opportunity)
                    AND RecordType.Name = 'Partner']) {
                        
Account oldAccount = Trigger.oldMap.get(acc.ID);

IF(acc.RecordTypeId != oldAccount.RecordTypeId ) {
    Trigger.New[0].addError('Cannot "Enable As Partner" an account with related opportunities.');}
    Else {Return;}
}
}

Do you have any idea ? 

Thanks,