Ajax (1) Apex Class (12) Apex Trigger (2) Community (2) Home Page (1) HTML (4) Integration (3) JS (7) KB (1) Label (1) Licenses (1) Listing (1) Log (1) OOPs (5) Sharing (1) Static Resource (1) Test Class (3) URI (1) Visualforce (10)

Tuesday 22 July 2014

correct code

var mplVals = '{! CH_Pre_Lead__c.Sub_Group__c }';
var mplValss2 = '{!CH_Pre_Lead__c.CH_Products__c }';
var mplSFID='00NO00000018kl3';
var mplSFID2='00NO00000018klS';
var mplVals1=new Array();
var mplVals2=new Array();
    mplVals1=mplVals.split(";");
    mplVals2=mplValss2.split(";");
var  params ='';
var  params2 ='';
var i;
var j;
for (i=0;i<mplVals1.length;i++)
{
params = params + mplSFID + '='+ mplVals1[i] + "&";
}
for (j=0;j<mplVals2.length;j++)
{
params2 = params2 + mplSFID2 + '='+ mplVals2[j] + "&";

}


var URL="/00Q/e?lea9={!CH_Pre_Lead__c.CH_Mobile__c}&lea11={!CH_Pre_Lead__c.CH_E_mail__c}&name_lastlea2={!CH_Pre_Lead__c.Pre_Lead_Last_Name__c}&lea3={!CH_Pre_Lead__c.CH_Company__c}&lea13={!CH_Pre_Lead__c.Lead_Status__c}&00NO00000018aoT={!CH_Pre_Lead__c.CH_Type_of_Requirement_1__c}&00NO00000018dMD={!CH_Pre_Lead__c.BU_Name__c}&name_firstlea2={!CH_Pre_Lead__c.Name}&recordtypeid=012O00000000SXkIAM&lea20={!CH_Pre_Lead__c.CH_Campaign__c}&00NO00000018dMD={!CH_Pre_Lead__c.BU_Name__c}&"+ params+'&'+params2;
parent.frames.location.replace(URL);

populate multipicklist

var mplVals = '{! CH_Pre_Lead__c.Sub_Group__c }';
var mplValss2 = '{!CH_Pre_Lead__c.CH_Products__c }';
var mplSFID='00NO00000018kl3';
var mplSFID2='00NO00000018klS';
var mplVals1=new Array();
var mplVals2=new Array();
    mplVals1=mplVals.split(";");
    mplVals2=mplValss2.split(";");
var  params ='';
var  params2 ='';
var i;
var j;
for (i=0;i<mplVals1.length;i++)
{
params = params + mplSFID + '='+ mplVals1[i] + "&";
}
for (j=0;j<mplVals2.length;j++)
{
params2 = params2 + mplSFID2 + '='+ mplVals2[i] + "&";
}


var URL="/00Q/e?lea9={!CH_Pre_Lead__c.CH_Mobile__c}&lea11={!CH_Pre_Lead__c.CH_E_mail__c}&name_lastlea2={!CH_Pre_Lead__c.Pre_Lead_Last_Name__c}&lea3={!CH_Pre_Lead__c.CH_Company__c}&lea13={!CH_Pre_Lead__c.Lead_Status__c}&00NO00000018aoT={!CH_Pre_Lead__c.CH_Type_of_Requirement_1__c}&00NO00000018dMD={!CH_Pre_Lead__c.BU_Name__c}&name_firstlea2={!CH_Pre_Lead__c.Name}&recordtypeid=012O00000000SXkIAM&lea20={!CH_Pre_Lead__c.CH_Campaign__c}&00NO00000018dMD={!CH_Pre_Lead__c.BU_Name__c}&"+ params+'&'+params2;
parent.frames.location.replace(URL);

Thursday 17 July 2014

Test Class for set and non-setup object



@isTest(SeeAllData=true)
public with sharing class clsForCaseShareUserTracker {

    static  testMethod  void validateshareCaseWithUser()
    {
       //User objUser=[Select id,User_License__c,ProfileId,AccountId,userRoleId from User where User_License__c='Partner Community' and IsActive=true  limit 1 ];
      //  update objUser;
       clsForCaseShareUserTracker objUtil=new clsForCaseShareUserTracker();
       Account objAccount1=objUtil.newAccount('Account1','platinum','Aurea','Indirect','Accept','German',123456,'Active','saasforce.in','IDEU');
       Contact objContact1=objUtil.newContact('Gupta',objAccount1.id,'TheKrrish@saasforce.in',true,'TheKrrish2@saasforce.in','password',false);
       Contact objContact2=objUtil.newContact('Singh',objAccount1.id,'TheKrrish2@saasforce.in',true,'TheKrrish@saasforce.in','password',false);
        RecordType rt=[SELECT Id, Name FROM RecordType WHERE SobjectType = 'Case' AND (Name = 'CS - Support Case' or Name = 'Platinum Services Case' ) limit 1];
        Case objCase1=objUtil.newCase('Users','Internal User','TheKrrish3@saasforce.in','Sales','medium',rt.id,objAccount1.id,'Problem','Extension');
        Profile p = [select id from profile where name='CS - Customer Portal User' limit 1];
        User objUser1=objUtil.newUser('TheKrrish4@saasforce.in',objContact1.id,'TheKrrish4@saasforce.in','Gupta','en_US','en_US','UTF-8','Als1',p.id,'America/Los_Angeles',true,'null');
         System.runAs (objUser1)
          {
List<UserRole> lstUserRole =[Select id from UserRole where PortalRole='Executive' and PortalAccountId=:objAccount1.id];
       User objUser2=objUtil.newUser('TheKrrish5@saasforce.in',objContact2.id,'TheKrrish5@saasforce.in','Gupta2','en_US','en_US','UTF-8','Als2',p.id,'America/Los_Angeles',true,lstUserRole[0].id);
     }
    
    }
    
    
    public Account newAccount(String name,String supportProgram,String LegalEntityName,String AccountChannel,String VersataEntity,String Language,Integer AnnualRevenue,String AccountType,String AccountDomainName,String AccountSubChannel )
    {
      Account objAccount = new Account();
       objAccount.Name = name;
       objAccount.Support_Program__c = supportProgram;
       objAccount.LegalEntityName__c = LegalEntityName;
       objAccount.Account_Channel__c = AccountChannel;
       objAccount.Versata_Entity__c = VersataEntity;
       objAccount.Language__c = Language;
       objAccount.Annual_Revenue__c = AnnualRevenue;
       objAccount.Account_Type__c =AccountType;
       objAccount.Account_Domain_Name__c =AccountDomainName; 
       objAccount.Account_SubChannel__c = AccountSubChannel;
       insert objAccount;
       return objAccount;
    }
    public Contact newContact(String lastName,String AccountId,String Email,Boolean IsPlatinumUser,String ContactUsername,String ContactPassword,Boolean IsTemporarypasswordSent)
    {
       Contact objContact = new Contact();
       objContact.LastName = lastName;
       objContact.AccountId = AccountId;
       objContact.Email = Email;
       objContact.Is_Platinum_User__c = IsPlatinumUser;
       objContact.Contact_Username__c = ContactUsername;
       objContact.Contact_Password__c = ContactPassword;
       objContact.Is_Temporary_password_Sent__c = IsTemporarypasswordSent;
       insert objContact;
       return objContact;
    }
    public Case newCase(String RequestType,String CVTypeofUserAccount,String AffectedUserEmailAddress,String AffectedBusinessUnit,String Priority,String RecordTypeid,String Accountid,String Type,String PlatinumServiceType)
    {
     Case objCase=new Case();
    objCase.Request_Type__c=RequestType;
    objCase.CV_Type_of_User_Account__c=CVTypeofUserAccount;
    objCase.Affected_User_s_Email_Address__c=AffectedUserEmailAddress;
    objCase.Desired_Effective_Date__c=system.today();
    objCase.Affected_Business_Unit__c=AffectedBusinessUnit;
    objCase.Priority=Priority;
    objCase.RecordTypeid=RecordTypeid;
    objCase.Accountid=Accountid;
    objCase.Type=Type;
    objCase.Platinum_Service_Type__c =PlatinumServiceType;
    insert objCase; 
    return objCase;
    }
    public User newUser(String Email,String ContactId,String Username,String LastName,String languagelocalekey,String localesidkey ,String emailencodingkey,String alias,String profileid,String timezonesidkey,Boolean IsActive,String userRoleId)
    {
         User objUser= new User();
         objUser.Email=Email;
         objUser.ContactId=ContactId;
         objUser.Username =Username;
         objUser.LastName=LastName;
         objUser.languagelocalekey=languagelocalekey;
         objUser.localesidkey=localesidkey;
         objUser.emailencodingkey=emailencodingkey;
         objUser.alias = alias;
         objUser.profileid = profileid;
         objUser.timezonesidkey=timezonesidkey;
         objUser.IsActive =IsActive;
             if(userRoleId!='null' && userRoleId!='NULL' && userRoleId!='Null')
             {
             objUser.userRoleId=userRoleId;
             }
         insert objUser;
         return objUser;
    }

}

Wednesday 16 July 2014

New way for Trackers

@isTest(SeeAllData=true)
public with sharing class clsForCaseShareUserTracker {

    static  testMethod  void validateshareCaseWithUser()
    {
       //User objUser=[Select id,User_License__c,ProfileId,AccountId,userRoleId from User where User_License__c='Partner Community' and IsActive=true  limit 1 ];
      //  update objUser;
       clsForCaseShareUserTracker objUtil=new clsForCaseShareUserTracker();
       Account objAccount1=objUtil.newAccount('Account1','platinum','Aurea','Indirect','Accept','German',123456,'Active','saasforce.in','IDEU');
       Contact objContact1=objUtil.newContact('Gupta',objAccount1.id,'TheKrrish@saasforce.in',true,'TheKrrish2@saasforce.in','password',false);
       Contact objContact2=objUtil.newContact('Singh',objAccount1.id,'TheKrrish2@saasforce.in',true,'TheKrrish@saasforce.in','password',false);
        RecordType rt=[SELECT Id, Name FROM RecordType WHERE SobjectType = 'Case' AND (Name = 'CS - Support Case' or Name = 'Platinum Services Case' ) limit 1];
        Case objCase1=objUtil.newCase('Users','Internal User','TheKrrish3@saasforce.in','Sales','medium',rt.id,objAccount1.id,'Problem','Extension');
        Profile p = [select id from profile where name='CS - Customer Portal User' limit 1];
        User objUser1=objUtil.newUser('TheKrrish4@saasforce.in',objContact1.id,'TheKrrish4@saasforce.in','Gupta','en_US','en_US','UTF-8','Als1',p.id,'America/Los_Angeles',true,'null');
         List<UserRole> lstUserRole =[Select id from UserRole where PortalRole='Executive' and PortalAccountId=:objAccount1.id];
        User objUser2=objUtil.newUser('TheKrrish5@saasforce.in',objContact2.id,'TheKrrish5@saasforce.in','Gupta','en_US','en_US','UTF-8','Als1',p.id,'America/Los_Angeles',true,lstUserRole[0].id);
    }
    
    
    public Account newAccount(String name,String supportProgram,String LegalEntityName,String AccountChannel,String VersataEntity,String Language,Integer AnnualRevenue,String AccountType,String AccountDomainName,String AccountSubChannel )
    {
      Account objAccount = new Account();
       objAccount.Name = name;
       objAccount.Support_Program__c = supportProgram;
       objAccount.LegalEntityName__c = LegalEntityName;
       objAccount.Account_Channel__c = AccountChannel;
       objAccount.Versata_Entity__c = VersataEntity;
       objAccount.Language__c = Language;
       objAccount.Annual_Revenue__c = AnnualRevenue;
       objAccount.Account_Type__c =AccountType;
       objAccount.Account_Domain_Name__c =AccountDomainName;
       objAccount.Account_SubChannel__c = AccountSubChannel;
       insert objAccount;
       return objAccount;
    }
    public Contact newContact(String lastName,String AccountId,String Email,Boolean IsPlatinumUser,String ContactUsername,String ContactPassword,Boolean IsTemporarypasswordSent)
    {
       Contact objContact = new Contact();
       objContact.LastName = lastName;
       objContact.AccountId = AccountId;
       objContact.Email = Email;
       objContact.Is_Platinum_User__c = IsPlatinumUser;
       objContact.Contact_Username__c = ContactUsername;
       objContact.Contact_Password__c = ContactPassword;
       objContact.Is_Temporary_password_Sent__c = IsTemporarypasswordSent;
       insert objContact;
       return objContact;
    }
    public Case newCase(String RequestType,String CVTypeofUserAccount,String AffectedUserEmailAddress,String AffectedBusinessUnit,String Priority,String RecordTypeid,String Accountid,String Type,String PlatinumServiceType)
    {
     Case objCase=new Case();
    objCase.Request_Type__c=RequestType;
    objCase.CV_Type_of_User_Account__c=CVTypeofUserAccount;
    objCase.Affected_User_s_Email_Address__c=AffectedUserEmailAddress;
    objCase.Desired_Effective_Date__c=system.today();
    objCase.Affected_Business_Unit__c=AffectedBusinessUnit;
    objCase.Priority=Priority;
    objCase.RecordTypeid=RecordTypeid;
    objCase.Accountid=Accountid;
    objCase.Type=Type;
    objCase.Platinum_Service_Type__c =PlatinumServiceType;
    insert objCase;
    return objCase;
    }
    public User newUser(String Email,String ContactId,String Username,String LastName,String languagelocalekey,String localesidkey ,String emailencodingkey,String alias,String profileid,String timezonesidkey,Boolean IsActive,String userRoleId)
    {
         User objUser= new User();
         objUser.Email=Email;
         objUser.ContactId=ContactId;
         objUser.Username =Username;
         objUser.LastName=LastName;
         objUser.languagelocalekey=languagelocalekey;
         objUser.localesidkey=localesidkey;
         objUser.emailencodingkey=emailencodingkey;
         objUser.alias = alias;
         objUser.profileid = profileid;
         objUser.timezonesidkey=timezonesidkey;
         objUser.IsActive =IsActive;
             if(userRoleId!='null' && userRoleId!='NULL' && userRoleId!='Null')
             {
             objUser.userRoleId=userRoleId;
             }
         insert objUser;
         return objUser;
    }

}

Thursday 3 July 2014

sObjects That Cannot Be Used Together in DML Operations

sObjects That Cannot Be Used Together in DML Operations

DML operations on certain sObjects can’t be mixed with other sObjects in the same transaction. This is because some sObjects affect the user’s access to records in the organization. These types of sObjects must be inserted or updated in a different transaction to prevent operations from happening with incorrect access level permissions. For example, you can’t update an account and a user role in a single transaction. However, there are no restrictions on delete DML operations.

The following sObjects can’t be used with other sObjects when performing DML operations in the same transaction:
  • FieldPermissions
  • Group

    You can only insert and update a group in a transaction with other sObjects. Other DML operations are not allowed.

  • GroupMember

    You can only insert and update a group member in a transaction with other sObjects in Apex code saved using Salesforce.com API version 14.0 and earlier.

  • ObjectPermissions
  • PermissionSet
  • PermissionSetAssignment
  • QueueSObject
  • ObjectTerritory2AssignmentRule
  • ObjectTerritory2AssignmentRuleItem
  • RuleTerritory2Association
  • SetupEntityAccess
  • Territory2
  • Territory2Model
  • UserTerritory2Association
  • User

    You can insert a user in a transaction with other sObjects in Apex code saved using Salesforce.com API version 14.0 and earlier.

    You can insert a user in a transaction with other sObjects in Apex code saved using Salesforce.com API version 15.0 and later if UserRoleId is specified as null.

    You can update a user in a transaction with other sObjects in Apex code saved using Salesforce.com API version 14.0 and earlier

    You can update a user in a transaction with other sObjects in Apex code saved using Salesforce.com API version 15.0 and later if the following fields are not also updated:
    • UserRoleId
    • IsActive
    • ForecastEnabled
    • IsPortalEnabled
    • Username
    • ProfileId
  • UserRole
  • UserTerritory
  • Territory
  • Custom settings in Apex code saved using Salesforce.com API version 17.0 and earlier.

If you are using a Visualforce page with a custom controller, you can only perform DML operations on a single type of sObject within a single request or action. However, you can perform DML operations on different types of sObjects in subsequent requests, for example, you can create an account with a save button, then create a user with a submit button.

You can perform DML operations on more than one type of sObject in a single class using the following process:
  1. Create a method that performs a DML operation on one type of sObject.
  2. Create a second method that uses the future annotation to manipulate a second sObject type.

This process is demonstrated in the example in the next section.

Example: Using a Future Method to Perform Mixed DML Operations

This example shows how to perform mixed DML operations by using a future method to perform a DML operation on the User object.

    public class MixedDMLFuture {      public static void useFutureMethod() {          // First DML operation          Account a = new Account(Name='Acme');          insert a;                    // This next operation (insert a user with a role) 
        // can't be mixed with the previous insert unless
        // it is within a future method.
        // Call future method to insert a user with a role. Util.insertUserWithRole( 'mruiz@awcomputing.com', 'mruiz', 'mruiz@awcomputing.com', 'Ruiz'); } }
    public class Util {      @future
    public static void insertUserWithRole( String uname, String al, String em, String lname) { Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; UserRole r = [SELECT Id FROM UserRole WHERE Name='COO']; // Create new user with a non-null user role ID User u = new User(alias = al, email=em, emailencodingkey='UTF-8', lastname=lname, languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id, userroleid = r.Id, timezonesidkey='America/Los_Angeles', username=uname); insert u; } }

find month between dates

date.valueof(agr.get('expr0')).monthsBetween(objInvL.Cl_Bill_Date__c)