• kevin.chiles
  • NEWBIE
  • 125 Points
  • Member since 2013

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 25
    Questions
  • 56
    Replies

Hello 

 

I am trying to Cover this trigger

 

trigger addContactRole on Opportunity (after Insert, after update) {

List<OpportunityContactRole> newContactRoleList=new List<OpportunityContactRole>();
List<OpportunityContactRole> oldContactRoleList=new List<OpportunityContactRole>();
Set<Id> OppId=new Set<Id>();
Set<Id> ContactId=new Set<Id>();

for(Opportunity oppObj: Trigger.new)
{
//Insert condition
if(Trigger.isInsert)
{
if(oppObj.Contact__c!=null )
{
//Creating new contact role
newContactRoleList.add(new OpportunityContactRole (ContactId=oppObj.Contact__c,OpportunityId=oppObj.Id, Role='Decision Maker', IsPrimary = true));

}
}
else
{

if(oppObj.Contact__c==null && Trigger.oldMap.get(oppObj.Id).Contact__c!=null)
{
//Getting the contact and oppty Id from old values and adding this in set
Opportunity OldoppObj=Trigger.oldMap.get(oppObj.Id);
OppId.add(OldoppObj.id);
ContactId.add(OldoppObj.Contact__c);

}
else if(oppObj.Contact__c!=null && Trigger.oldMap.get(oppObj.Id).Contact__c==null)
{
//Creating new contact role
newContactRoleList.add(new OpportunityContactRole (ContactId=oppObj.Contact__c, OpportunityId=oppObj.Id, Role='Decision Maker', IsPrimary = true));
}
}
}


try
{
//inserting new Contacts
if(newContactRoleList.size()>0) insert newContactRoleList;

//Selecting old contact roles
if (OppId.size()>0) oldContactRoleList=[Select Id from OpportunityContactRole where ContactId in : ContactId and OpportunityId in : OppId];

//Deleting old contact roles
if (oldContactRoleList.size()>0) delete oldContactRoleList;
}
catch(Exception e)
{
System.debug(e);
//trigger.new[0].addError('Technical error occurred. Please contact to your system administrator or try after some time.');

}

 


}

 

 

but I cannot get my code coverage over 73 percent.

 

here is my test class to cover this code so far.  Can anyone help me with this?

 

@isTest(SeeAllData=true)


private class TestaddContactRole {

static testmethod void TestaddContactRole() {


Test.startTest();
Business_Account__c b= new Business_Account__c(Name='Btest');
b.Customer_Type__c='Industry';

insert b;

Account a= new Account(Name='Test');
a.Business_Account__c=b.Id;
a.Lab_Purpose__c='Manufacturing';
a.Address__c='test';
a.City__c='test';
a.Country__c='United States';
a.Region__c='AMER';
a.Bill_To__c=true;


insert a;

// Create contacts
Contact ct1 = new Contact(AccountId=a.Id);
Contact ct2 = new Contact(AccountId=a.Id);

ct1.FirstName = 'Larrys';
ct1.LastName = 'Page';
ct2.FirstName = 'Larrys';
ct2.LastName = 'Page';

Insert ct1;
Insert ct2;




// Create Opportunity
Opportunity op1 = new Opportunity(AccountId=a.Id,Contact__c = ct1.Id,Bill_To_Lab__c=a.Id);
op1.Region__c='AMER';
op1.Buy_Gatan__c='100% - Wants Gatan, No Doubt';
op1.Buy__c='100% - Funding is secured';
op1.name = 'Test';
op1.CloseDate = Date.today()+2;
op1.StageName = 'EVALUATION';
op1.Sales_Channel__c='Distributor';



Database.SaveResult sr1 = Database.insert(op1, true);
System.assert(sr1.isSuccess());
system.debug('Inserted new opportunity');

// Update Opportunity with new contact

op1.Contact__c = ct2.Id;
//update op1;
Database.SaveResult sr2 = Database.update(op1, true);
System.assert(sr2.isSuccess());
system.debug('Opportunity updated');

Test.stopTest();
System.assert(sr2.isSuccess());

}

}

Hello!

 

I am trying to match commissions based on incentives, and divisions associated.  I have tried the following trigger but am fairly new to apex code when it comes to larger statements such as this one.  Can anyone help me out?  Here is my code

 

trigger CreateCommission on Commissionable_User__c (after insert ) {

for (Commissionable_User__c CU: trigger.new){

  Incentive_Plan__c[] InP = [Select Id, Spiff__c, of_Commissionable_Price__c, Division__c From Incentive_Plan__c Where Division__c = :CU.Commissionable_User_Division__c limit 1 ];
   Incentive_Product__c[] IPa=[Select Id,Intradivisional_Percentage__c,Interdivisional_Percentage__c,Division__c ,Incentive_Plan__c From Incentive_Product__c Where Product__c= :CU.ProductId__c  limit 1 ];
   
  If(IPa.Id<>CU.ProductId__c&&InP.Division__c==CU.Commissionable_User_Division__c){
     
    
  Commission__c commission = new Commission__c();
  commission.Commission_User_ID__c = CU.Id;
  commission.earn_date__c =date.today();
  commission.Incentive_Plan__c = InP[0].Id;
  commission.Percent__c=InP[0].of_Commissionable_Price__c;
  commission.CommissionSpiff__c=InP[0].Spiff__c;
   
   ||
   
   If(IPa.Id==CU.ProductId__c&&IPa.Division__c<>CU.Commissionable_User_Division__c){
   
   Commission__c commission = new Commission__c();
  commission.Commission_User_ID__c = CU.Id;
  commission.earn_date__c =date.today();
  commission.Incentive_Plan__c = InP[0].Id;
  commission.Percent__c=InP[0].Interdivisional_Percentage__c;
  commission.CommissionSpiff__c=InP[0].Spiff__c;
  
  ||
  
   If(IPa.Id==CU.ProductId__c&&IPa.Division__c==CU.Commissionable_User_Division__c){
   
    Commission__c commission = new Commission__c();
  commission.Commission_User_ID__c = CU.Id;
  commission.earn_date__c =date.today();
  commission.Incentive_Plan__c = InP[0].Id;
  commission.Percent__c=InP[0].Intradivisional_Percentage__c;
  commission.CommissionSpiff__c=InP[0].Spiff__c;
   
   else
   
   Commission__c commission = new Commission__c();
  commission.Commission_User_ID__c = CU.Id;
  commission.earn_date__c =date.today();
  commission.Incentive_Plan__c = InP[0].Id;
  commission.Percent__c=InP[0].of_Commissionable_Price__c;
  commission.CommissionSpiff__c=InP[0].Spiff__c;
  
  insert commission;
    
   
}
}






}

 

 

I am trying to add a product into a lookup field on my custom object Category_Item__c.  The lookup field is Item__c.  I am trying to match on the Names of the records, for instance.  Producta is the name of the Category Item and Producta is the name of my product, if these 2 are the same the product lookup should populate with the product id, and tie the two records together.  Here is what I have so far.

 

trigger ProductAssociation on Category_Item__c (after insert, after update) { for(Category_Item__c cid:[select Id, CatName__c from Category_Item__c]);{ Product2 prod = [Select Id From Product2 Where Product_Name__c = cid.CatName__c]; for(Category_Item__c cid: trigger.new) if(cid.Item__c==null) cid.Item__c== prod; update Category_Item__c; } }

 

I keep getting unexpected token errors on line 4 for my field CatName__c.  this is stating that the variable does not exist even though I am stating it in the 2nd line.  What am I doing wrong here?

Hello!

 

I have 2 objects, a ship to and an account.  If a user has access to the ship tochild record they should also have access to the account.  Access is granted by the Saels Rep Code on the ship to record.  This will need to match the Rep ID on the user record.  So far this is what I have.  I continue to get User.Rep__ID__c at line 7 unexpected token.  Any thoughts or code correction are greatly appreciated.  Thanks!

trigger shareSPA on InForceEW__shipto__c (after insert, after update) {

  //SPA_Share is the share table that was created when the OWD was set to "Private"
  List <Ship_To_Sharing> shiptoShares = new List <Ship_To_Sharing>();
  
  for(User us:[select Id, Rep_ID__c from User]);
  for (InForceEW__shipto__c st : [select Id,InForceEW__Account__c,Sales_Rep_Code__c From InForceEW__shipto__c Where Sales_Rep_Code__c=User.Rep_ID__c];  {


    if (trigger.isInsert) {
      Ship_To_Sharing shiptoShares = new Ship_To_Sharing();
      shiptoShares.ParentId = st.InForceEW__Account__c;
      shiptoShares.UserOrGroupId = st.Sales_Rep_Code__c;
      shiptoShares.AccessLevel = 'edit';
      shiptoShares.RowCause = Schema.Ship_To_Sharing.RowCause.ShipToSharing__c;
        
      shiptoShares.add(shiptoShare);
    }
    if (trigger.isUpdate) {
      InForceEW__shipto__c oldShipTo = Trigger.oldMap.get(shp.Id);
      if(shp.Sales_Rep_Code__c != oldDiscount.Sales_Rep_Code__c) {
      Ship_To_Sharing shiptoShares = new Ship_To_Sharing();
      shiptoShares.ParentId = st.InForceEW__Account__c;
      shiptoShares.UserOrGroupId = st.Sales_Rep_Code__c;
      shiptoShares.AccessLevel = 'edit';
      shiptoShares.RowCause = Schema.Ship_To_Sharing.RowCause.ShipToSharing__c;
        
        shiptoShares.add(shiptoShare);      
      }
    }
  }

  Database.SaveResult[] shiptoShareInsertResult = Database.insert(shiptoShares, false);

}
}

 

 

Hello, 

 

I am trying to make a commission__c record change record type, if a field is equal to a value.  Any help here would be awesome!  This is what I have so far

 

trigger updaterecordtype on Commission__c (after insert) {

RecordType rt = [select Id,Name from RecordType where Name = 'Refunds' and SobjectType = 'Commission__c'];

for(Commission__c c =[select Id, RecordTypeId from Commission__c Where Payment_Id__c ='Refund'];

c.RecordTypeId=rt;)

update c;

}

 

Hello!

 

I am trying to update the record type of child objects.  These need to be updated when the payment (parent) is set to a specific status of "reversed" this should update my child object "commissions" to a record type of returns.  It saves and compiles but does not seem to fire and I cannot figure out why!  Help me Obi Wan, your my only hope....

 

trigger CommsReturn on pymt__PaymentX__c (after insert, after update) {
    List<pymt__PaymentX__c> updatePayList = new List<pymt__PaymentX__c>();
    RecordType ReturnRT = [Select Id From RecordType Where Name = 'Returns'];
    
    RecordType CommRT2 = [Select Id From RecordType Where Name = 'Commissions'];
    
    
    //Loop through the case and update the account with appropriate category
    set<ID> PayIds = new set<ID>();
    for( pymt__PaymentX__c p1 : Trigger.New){
        if(p1.Id != null) 
            PayIds.add(p1.Id);
    }
    if(!PayIds.isEmpty()){
        list<Commission__c> csList = [select Payment_ID__c, RecordTypeId  from Commission__c where Payment_ID__c = : PayIds];
        map<Id, pymt__PaymentX__c> PayUpdates = new map<ID, pymt__PaymentX__c>();
        for(Commission__c cs : csList){
            pymt__PaymentX__c pmt = PayUpdates.get(cs.Payment_ID__c);
            if(pmt == null)
                pmt = new pymt__PaymentX__c(Id = cs.Payment_ID__c);

            if(pmt.pymt__Status__c != 'Reversed')
                cs.RecordType = ReturnRT ;
                else
                cs.RecordType =CommRT2 ;
            

            PayUpdates.put(cs.Payment_ID__c, pmt);
        }
        
        update PayUpdates.Values();
    }
}

Hello

 

I am trying to make sure that if a case is open for an account that they cannot be contacted.  This is what I have so far, but it does not seem to work.  Once the case is closed an no other open cases exist, the check box should be removed

 

trigger DoNotContactAccount on Case (after insert, after update) {
List<Account> updateAccList = new List<Account>();

//Loop through the case and update the account with appropriate category
set<ID> AccIds = new set<ID>();
for( Case c1 : Trigger.New){
if(c1.AccountId != null && c1.Do_Not_Contact__c != null)
AccIds.add(c1.AccountID);
}
if(!AccIds.isEmpty()){
list<Case> caseList = [select AccountID, Do_Not_Contact__c from Case where AccountId = : AccIds];
map<Id, Account> AccountUpdates = new map<ID, Account>();
for(Case cs : caseList){
Account acc = AccountUpdates.get(cs.AccountID);
if(acc == null)
acc = new Account(Id = cs.AccountId);

if(cs.Status != 'Closed')
acc.PersonHasOptedOutOfEmail = true;
else
acc.PersonHasOptedOutOfEmail = false;

AccountUpdates.put(cs.AccountID, acc);
}

update AccountUpdates.Values();
}
}

Hello!

 

I have a custom object that I am pulling commissions into from another object, incentive_plan.  I have products associated to this incentive plan via a related list.  I also have users, I can get my trigger to filter via the associated user, but am having a pickle of a time associating the product portion to make sure that this matches.  here is what I have so far that saves

trigger CreateCommission on Commissionable_User__c (after insert )

{ for (Commissionable_User__c CU: trigger.new){
Assigned_user__c[] asu = [Select Id, Spiff__c,Percent__c,Incentive_Plan__c From Assigned_user__c Where User__c = :CU.Commissionable_User__c limit 1 ];

Commission__c commission = new Commission__c();
commission.Commission_User_ID__c = CU.Id;
commission.earn_date__c =date.today();
commission.Incentive_Plan__c = asu[0].Incentive_Plan__c;
commission.Percent__c=asu[0].Percent__c;
commission.CommissionSpiff__c=asu[0].Spiff__c;
insert commission; } }

 The question is, how to I get data from my other related list Incentive_Products__c to match the related product ID on my commission object?  the Product.id is a formula field that is being pulled in from its parent object that hosts the product itself.  

 

 

Hello!  I have a few things I am trying to do but I cannot seem get my head around this correctly.  Firstly, to explain my plight, I am trying to get data populated from a few different tables into one.  I am also trying to auto generate the record that would host all of this inforation.  Basically, I have an incentives object, and a commissions object.  The incentives object has several products in  a related list (incentive products) associated to it.  Incentives also has User associated to them (another related list)  I need to look at my payment objects and say. Ok, when payment comes in pull the related User(commissionable user) and auto calculate a commission based on what incentive prog.  he is assigned. to.  This sounds nuts so implementation  will be a snow storm im sure.  Thanks!

 

What I have so far, but is probably wrong

 

trigger IncentiveAssociation on Commission__c (after insert) {

for(Assigned_User__c AU: trigger.new){
[Select Id from Assigned_User__c ];

for (Incentive_Plan__c IP: trigger.new){
[Select Id from Incentive_Plan__c];

for (Commissionable_User__c CU : trigger.new) {
[Select Id From User Where CU.Commissionable_User__c = AU.User__c];

for (Incentive_Products__c ICP: trigger.new){
[Select Id from Incentive_Products__c.Product__c]


Id recId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('New InstallBase').getRecordTypeId();
for (Commission__c C : trigger.new){
if(trigger.isInsert){
C.RecordTypeId=recId;
C.Incentive_Plan__c=IncentivePlan;
C.Percentage__c=IP.of_Commissionable_Price__c;
C.Spiff__c=IP.Spiff__c;
C.Product=[Select Id from P.Product
}

 

Hello!

 

I am having an error when I try to save my code.  This is stating that the object I am referencing is not accessible.  If anyone has any Ideas please let me know!  this has me stumped!

 

trigger AutoCreateCommissionableUser on pymt__PaymentX__c (after insert) {
List<Commissionable_User__c> CU = new List<Commissionable_User__c>();

for (pymt__PaymentX__c newPayment: Trigger.New) {

if (pymt__PaymentX__c.pymt__Contact__c <> null) {

CU.add(new Commissionable_User__c(

RecordTypeId = [select Id from RecordType where Name = 'Payment' and SobjectType = 'Commissionable_User__c'].Id,

Payment__c =Payment.Id,
Commissionable_User__c =pymt__PaymentX__c.Owner.Id ,
Owner=pymt__PaymentX__c.Owner.Id

));

}

}

insert CU;

}

Hello!

 

I have a custom button that creates a pdf and emails it to a client from a custom object.  I now want to have the button only work when the record has a status of approved.  I have a status field Status__c, with multiple values, Approved being the one I want to have the fire off of.  I am not sure how to accomplish this.  The button is referencing a visual force page, and I am not sure if this condition needs to be set on the VF page or in the button (on click java script).  Any suggestions? 

I am trying to execute this custom handler for my object, and its related child records.  For some reason (probably an obvious one) I cannot seem to get this to work correctly and keep getting errors when I go to save.  Is there any assistance that could be given?

 

public with sharing class CustomSPAPartyMasterHandler {
    public static final String relRegexName = '[<][a-zA-Z0-9\\s="^#!{}_.]*';
    public static final String endChild = '</';
    public static final String endNode = '>';
    public static final String firstMatchedChild = '(.)*?';
    public static final String regexObjField = '[{][!][\\w.]+[}]';
    public static final String emptyString = '';
    
    //Empty Constructor
    public CustomSPAPartyMasterHandler() {
        
    }
    
    //Generate XML for multiple SPA Discounts
    public static String handleSPADiscount() {
        String relName = 'relationName="#SPA_Discount__r:SPA_Discount__c#"';
        String message = '<?xml version="1.0"?><ProcessSPA><SPA><SPA_Discount relationName="#SPA_Discount__r:SPA_Discount__c#"><Name>{!SPA_Discount__r.Name}</Name><Catalog>{!SPA_Discount__r.Catalog__c}</Catalog><AWC Free Freight>{!SPA_Discount__r.AWC_F_Frt__c}</AWC Free Freight><Reason>{!SPA_Discount__r.Reason__c}</Reason><CompetitorName>{!SPA_Discount__r.Competitor_Name__c}</CompetitorName><SalesCommisionSplit>{!SPA_Discount__r.Sales_Commision_Split__c}</SalesCommisionSplit></Optionforsplitchoice>{!SPA_Discount__r.Option_For_SPlit_Choice__c}</Optionforsplitchoice><Shiptorepfirstname>{!SPA_Discount__r.Ship_To_Rep_First_Name__c}</Shiptorepfirstname><Shiptolastname>{!SPA_Discount__r.Ship_To_Rep_Last_Name__c}</Shiptolastname><Discounttype>{!SPA_Discount__r.Discount_Type__c}</Discounttype><Netprice>{!SPA_Discount__r.Net_Price__c}</Netprice><Discountlevel>{!SPA_Discount__r.Discount_Level__c}</Discountlevel><Spiff>{!SPA_Discount__r.Spiff__c}</Spiff><Netexpectedordervalue>{!SPA_Discount__r.Net_Expected_Order_Value__c}</Netexpectedordervalue><Minimumorderquantity>{!SPA_Discount__r.Minimum_Order_Quantity}</Minimumorderquantity><PartNumber>{!SPA_Discount__r.Part_Number__c}</PartNumber></SPAdiscount></ProcessSPA>';
        String SPADiscountXML = getChildXml(message, relName);
        List<SPA_Discount__c> SPADiscountLst = null;
    
        String spQuery= 'Select  sp.Id, ' +
                    ' (Select Name, SPA_Agreement__c,Catalog__c, Reason__c, Competitor_Name__c, Sales_Commision_Split__c, Option_For_Split_Choice__c, Ship_To_Rep_First_Name__c, Ship_To_Rep_Last_Name__c, AWC_F_Frt__c, Part_Number__c,Minimum_Order_Quantity,Net_Expected_Order_Value__c,Spiff__c,Discount_Level__c,Net_Price__c,Discount_Type__c,Ship_To_Rep_Last_Name__c' + 
                    ' From SPA_Discount__r) From SPA__c sp';
        list<SPA__c> lstSPA = database.query(spQuery);
        if(lstSPA != null && lstSPA .size()  > 0 ){
            SPA__c SPA= lstSPA [0];
            SPADiscountLst = lstSPA[0].SPA_Discount__r; 
        }
        if(SPADiscountLst !=null && !SPADiscountLst.isEmpty()) {
            List<String> fields = getFieldsFromXmlPart(SPADiscountXML);
            if(fields != null && !fields.isEmpty()) {
                String childXml;
                String allChildXml = '';
                for(SPA_Discount__c spadiscount: SPADiscountLst){
                    childXml = SPADiscountXML;
                    for(Integer cnt=0;cnt<fields.size();cnt++){
                        String objName = fields[cnt].split('\\.')[0];
                        string fldname = fields[cnt].split('\\.')[1];       
                        childXml = childXml.replace('{!'+fields[cnt]+'}',
                            htmlEncode(String.valueOf(personBillingAddress.get(fldname))));
                    }
                    allChildXml = allChildXml + childXml;
                }
                
                if(allChildXml!='')
                {
                    allChildXml = allChildXml.replace(' ' + relName, emptyString);
                    message = message.replace(SPADiscountXML, allChildXml);
                }
            }
        }
        return message;
    }
    
    //get SPA_Discount from the main XML
    public static String getChildXml(String message, String searchString) {
        Pattern patt;
        Matcher mat;
        string regex = relRegexName+searchString+endNode;
        patt =Pattern.compile(regex);
        system.debug('--- search string>>' + regex);
        mat=patt.matcher(message);
        String elm;
        if(mat.find()){
            elm = mat.group(0);
        }
        System.debug('mat.grp>> '+ elm);
        if(elm!=null && elm!=''){
            elm=elm.replace('>','/>');
            DOM.Document domDoc = new DOM.Document();
            domDoc.load(elm);
            Dom.XmlNode rootXmlNode = domDoc.getRootElement();
            String rootNodeName = rootXmlNode.getName();
            System.debug(rootNodeName);
            String endTag = endChild + rootNodeName + endNode;
            regex = relRegexName+searchString+endNode+firstMatchedChild+endTag;
            System.debug('>>>full regex: '+regex);
            patt =Pattern.compile(regex);
            mat=patt.matcher(message);
            if(mat.find()){
                elm = mat.group(0);
            }
            System.debug('mat.grp>> '+ elm);
        }
        return elm;
    }
    
    //get fields from xml
    public static List<String> getFieldsFromXmlPart(String xml) {
        Pattern patt;
        Matcher mat;
        List<String> fields = new List<String>();
        patt = Pattern.compile(regexObjField);
        System.debug('xml>>>>' + xml);
        if(xml != '' && xml != null) {
            mat = patt.matcher(xml);
            while(mat.find()){
                String fieldName =  mat.group();
                fieldName = fieldName.replace('{!','');
                fieldName = fieldName.replace('}','');
                fields.add(fieldName);
            }
        } 
        return fields;
    }
    
    public static string htmlEncode(String str) {
        if(!StringUtil.isNull(str))
            return str.Replace('&', '&amp;').Replace('<', '&lt;').Replace('>', '&gt;').Replace('\"', '&quot;').Replace('\'', '&apos;');
        else return str;
    }
}

 

 

Hello!

 

I am writing a validation rule that would (in theory) work like this.  If the Status field is Approved, or Pending Renewal, then the End date on the record can be pushed out to 1 YEAR past its current original end date (date field stamped on the record.

 

I can get this to work on the 1 picklist value (approved) and it works fine, but when I try to add logic to add the additional value, it wont let me save the record even though it does not meet the criteria needed for this to not fire.  

 

NOT(IsPICKLIST(Status__c,"Approved")&&End_Date__c+365>Original_End_Date__c ||

NOT(ISPICKLIST(Status_c,"Pending Renewal")&&End_Date__c+365>Original_End_Date__c)

 

So you would this this word work correctly, but it seems to want to fire the rule every time no matter what.  Is there something small that Im missing?

I am trying to bring over quote lines to my custom object as SPA linesbut I am having some issues.  Currently the trigger is telling me I am using the wrong Object and that I should be using Quote, but I am entering these items as Line items under my SPA from quote.  Am I going crazy?

 

here is my code

 

trigger test1 on SPA__c (after insert)
{

SPA__c to=trigger.new[0];

Quote q=[select id from Quote where id=:to.Volume_Price_Quote__c];

list<QuoteLineItem> ql=[select id,ListPrice,PriceBookEntry.Product2Id ,Subtotal,TotalPrice from QuoteLineItem where QuoteId=:q.id];

 

for(QuoteLineItem qli:ql)

{

SPA_Discount__c sd=new SPA_Discount__c();

 

sd.Net_Price__c=qli.ListPrice;
sd.SPA_Discount_for__c=qli.Product_Name__c;
sd.Public_Notes__c=qli.Public_Notes__c;
sd.Private_Notes__c=qli.Private_Notes__c;
sd.Sales_Commision_Split__c=qli.Sales_Commission_Split__c;
sd.Option_For_Split_Choice__c=qli.Option_For_Split_Choice__c;
sd.Spiff__c=qli.Spiff__c;


insert sd;
}
}

Hi,

 

I am having an issue with my test class not being able to save. the error I get is Unexpected token "insert"at line 16

 

Not sure why this is happening as this has never happened for this type of test class before.  Here is the code for the creation of an account and a custom object record called SPA

 

@isTest
public class triggerSPACRUD{
static testMethod void triggerSPACRUD(){
//insert account
account acc = new account(
acc.Name='test account');

insert acc;


SPA__c SPA = new SPA__c(
SPA.Recordtypeid= '012P00000004XHj',
SPA.Status__c = 'End User',
SPA.Dealer__c=acc.Id)
//fill all the required field and make sure your data passes the validation rules.
insert SPA;

}

 

Hello,

 

I am using a custom button on my custom object to return to the record for that object I just created.  However, this failing and sending me to the home page upon save.  Can anyone let me know what I am doing wrong?  Here is the button url

 

/a19/e?CF00NP0000000YeGC_lkid={!SPA__c.Id}&CF00NP0000000YeGC={!SPA__c.Name}&RecordType=012P00000004XK9&retURL=%2F{!SPA_Discount__c.Id}&saveURL=%2F{!SPA_Discount__c.Id}

 

My object is the SPA_Discount__c object.

Hello,

 

I am currently running into an error with my Java script.  The funny thing is a few days ago this worked perfectly, now it seems to fail.  Can anyone help me or tell me where I went wrong?  This is a custom button on Cases that creates an Opportunity.

 

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}

var opptyObj = new sforce.SObject("Opportunity");
var caseObj = new sforce.SObject("Case");
var today = new Date();
var sOpptyId = "{!Case.Opportunity__c}";

if( sOpptyId != "")
{
alert("This case is already tied to an opportunity!");
}
else
{
opptyObj.AccountId = "{!Case.AccountId}";
opptyObj.CloseDate = sforce.internal.dateTimeToString(today);
opptyObj.Description="{!Case.Description}";
opptyObj.Case__c = "{!Case.Id}";
opptyObj.Name = "{!Case.Subject}";
opptyObj.StageName = "Estimate in Progress";
opptyObj.Created_from_Case__c = "Y";
opptyObj.Type = "New Business";
opptyObj.Amount = .01;

var opptyresult = sforce.connection.create([opptyObj]);

if (opptyresult[0].success=='false')
{
alert("Opportunity creation failed: " + opptyresult[0].errors.message);
}
else
{
caseObj.Id = '{!Case.Id}';
caseObj.Opportunity__c = opptyresult[0].id;
caseObj.Status = "Estimate in Progress";

var caseResult = sforce.connection.update([caseObj]);

if(caseResult[0].success == 'false')
{
alert("Case update failed: " + caseResult[0].errors.message);
}
else
{
alert("An opportunity has been created and linked to this case.");
location.reload(true);
}
}
}

 

Hello!  I know that this seems like amateur hour everytime I post something, but I am struggling with something.  I need to always have the same product stamped onto my quote line items.  The need is because I have data coming from another system and there are far to many products to add into salesforce, so I am adding those names into a text field on the line items.  But, I need to have the lookup populated.  This needs to happen when the record is created.  Has anyone ever run into this use case?

Hello and Hold on to your hats folks I got a doosie! 

 

So the long and short is I am trying to implement a custom home page for my customer portal users.  This has 2 buttons, submit a case to support and submitt a case to dev.  I am using this class as a controller but I am not getting any coverage.

 

public class Home_Page_testsfdc {

    public Home_Page_testsfdc() {

    }

public Home_Page_testsfdc(ApexPages.StandardController controller) 
  {
  }
  
  public pagereference redirect1()
 {   
  
   pagereference p=new pagereference('https://cs8.salesforce.com/500/e?retURL=%2Fhome%2Fhome.jsp%3Fsdtd%3D1&#38;RecordType=012C0000000GGL3&#38;ent=Case');
  return p;
}
public pagereference redirect2()
 {   
  
   pagereference p=new pagereference('https://cs8.salesforce.com/500/e?retURL=%2Fhome%2Fhome.jsp%3Fsdtd%3D1&#38;RecordType=012C0000000GGL3&#38;ent=Case');
  return p;
}

}

 

The question then is, do I need to cover this code in the class itself or would I need to create a test class to cover this bad boy?  

 

 

Kev

 

Normaly my posts on here are quite challenging.  Todays might be just me not thinking this through enough.  I am trying to force a field to be populated when a case is closed.  Customer portal users can see this field but are not required to fill it out as it is read only.  I need this rule to negate teh close if it is a customer portal user.  Here is what I have so far

 

ISPICKVAL(Status,"Closed")&& ISPICKVAL(SIS_Priority_Setting__c," ")&& $Profile.Name <>"*5.5 Customer Portal Manager Custom" ||
ISPICKVAL(Status,"Closed")&&ISPICKVAL(SIS_Priority_Setting__c," ")&& $Profile.Name <>"ACP Customer Portal Manager" ||
ISPICKVAL(Status,"Closed")&& ISPICKVAL(SIS_Priority_Setting__c," ")&& $Profile.Name <>"High Volume Customer Portal User-SFDC Test" ||
ISPICKVAL(Status,"Closed")&& ISPICKVAL(SIS_Priority_Setting__c," ")&& $Profile.Name <>"High Volume Customer Portal User" ||
ISPICKVAL(Status,"Closed")&& ISPICKVAL(SIS_Priority_Setting__c," ")&& $Profile.Name <>"New Customer Portal"||

ISPICKVAL(Status,"Closed")&&ISPICKVAL(SIS_Priority_Setting__c," ")&& $Profile.Name <>"SSC Client Customer Portal Manager Custom"

 

Does this make sense or am I going mad?

 

Hello!

 

I am trying to match commissions based on incentives, and divisions associated.  I have tried the following trigger but am fairly new to apex code when it comes to larger statements such as this one.  Can anyone help me out?  Here is my code

 

trigger CreateCommission on Commissionable_User__c (after insert ) {

for (Commissionable_User__c CU: trigger.new){

  Incentive_Plan__c[] InP = [Select Id, Spiff__c, of_Commissionable_Price__c, Division__c From Incentive_Plan__c Where Division__c = :CU.Commissionable_User_Division__c limit 1 ];
   Incentive_Product__c[] IPa=[Select Id,Intradivisional_Percentage__c,Interdivisional_Percentage__c,Division__c ,Incentive_Plan__c From Incentive_Product__c Where Product__c= :CU.ProductId__c  limit 1 ];
   
  If(IPa.Id<>CU.ProductId__c&&InP.Division__c==CU.Commissionable_User_Division__c){
     
    
  Commission__c commission = new Commission__c();
  commission.Commission_User_ID__c = CU.Id;
  commission.earn_date__c =date.today();
  commission.Incentive_Plan__c = InP[0].Id;
  commission.Percent__c=InP[0].of_Commissionable_Price__c;
  commission.CommissionSpiff__c=InP[0].Spiff__c;
   
   ||
   
   If(IPa.Id==CU.ProductId__c&&IPa.Division__c<>CU.Commissionable_User_Division__c){
   
   Commission__c commission = new Commission__c();
  commission.Commission_User_ID__c = CU.Id;
  commission.earn_date__c =date.today();
  commission.Incentive_Plan__c = InP[0].Id;
  commission.Percent__c=InP[0].Interdivisional_Percentage__c;
  commission.CommissionSpiff__c=InP[0].Spiff__c;
  
  ||
  
   If(IPa.Id==CU.ProductId__c&&IPa.Division__c==CU.Commissionable_User_Division__c){
   
    Commission__c commission = new Commission__c();
  commission.Commission_User_ID__c = CU.Id;
  commission.earn_date__c =date.today();
  commission.Incentive_Plan__c = InP[0].Id;
  commission.Percent__c=InP[0].Intradivisional_Percentage__c;
  commission.CommissionSpiff__c=InP[0].Spiff__c;
   
   else
   
   Commission__c commission = new Commission__c();
  commission.Commission_User_ID__c = CU.Id;
  commission.earn_date__c =date.today();
  commission.Incentive_Plan__c = InP[0].Id;
  commission.Percent__c=InP[0].of_Commissionable_Price__c;
  commission.CommissionSpiff__c=InP[0].Spiff__c;
  
  insert commission;
    
   
}
}






}

 

 

I am trying to add a product into a lookup field on my custom object Category_Item__c.  The lookup field is Item__c.  I am trying to match on the Names of the records, for instance.  Producta is the name of the Category Item and Producta is the name of my product, if these 2 are the same the product lookup should populate with the product id, and tie the two records together.  Here is what I have so far.

 

trigger ProductAssociation on Category_Item__c (after insert, after update) { for(Category_Item__c cid:[select Id, CatName__c from Category_Item__c]);{ Product2 prod = [Select Id From Product2 Where Product_Name__c = cid.CatName__c]; for(Category_Item__c cid: trigger.new) if(cid.Item__c==null) cid.Item__c== prod; update Category_Item__c; } }

 

I keep getting unexpected token errors on line 4 for my field CatName__c.  this is stating that the variable does not exist even though I am stating it in the 2nd line.  What am I doing wrong here?

Hello

 

I am trying to make sure that if a case is open for an account that they cannot be contacted.  This is what I have so far, but it does not seem to work.  Once the case is closed an no other open cases exist, the check box should be removed

 

trigger DoNotContactAccount on Case (after insert, after update) {
List<Account> updateAccList = new List<Account>();

//Loop through the case and update the account with appropriate category
set<ID> AccIds = new set<ID>();
for( Case c1 : Trigger.New){
if(c1.AccountId != null && c1.Do_Not_Contact__c != null)
AccIds.add(c1.AccountID);
}
if(!AccIds.isEmpty()){
list<Case> caseList = [select AccountID, Do_Not_Contact__c from Case where AccountId = : AccIds];
map<Id, Account> AccountUpdates = new map<ID, Account>();
for(Case cs : caseList){
Account acc = AccountUpdates.get(cs.AccountID);
if(acc == null)
acc = new Account(Id = cs.AccountId);

if(cs.Status != 'Closed')
acc.PersonHasOptedOutOfEmail = true;
else
acc.PersonHasOptedOutOfEmail = false;

AccountUpdates.put(cs.AccountID, acc);
}

update AccountUpdates.Values();
}
}

Hi,

 

I have a custom field on the opportunity object named 'contact__c'. This is a simple lookup field.

If populated I want a trigger that creates an Opportunity contact role for that same contact.

 

Any ideas?

 

I can update the contact__c field based on the primary contact role but I need this work the other way round.

 

Any ideas?

 

Thanks

 

 

I am using a static resource which is our company's logo in a visualforce email.  I get the image to show up when previewing from the app but not when the email is delivered.  I noticed another post that indicates you may need to construct the url for the image in a different way (like in a controller class).  Any ideas?

 

<apex:image value="{!URLFOR($Resource.ZayoLogo)}"/>

 

 

  • December 14, 2009
  • Like
  • 0

Has anyone solved this problem?

 

We send out a lot of automatic notification emails to our partners.  We want our Partners to be able to click on links within the notification emails and get directed to the relevant records within their partner portal.

 

The problem we are experiencing is that even though they have an already open Partner Portal when they click on the link they get force to re-login.  Very frustrating and annoying experience.  

 

So, we are wondering if anyone else has this problem and has perhaps solved it? 

  • November 11, 2009
  • Like
  • 0