You need to sign in to do that
Don't have an account?
Create / Enable new SelfServiceUser when contact is created
I need to create enable a new SelfServiceUser when a contact of specific record type is created.
This is what I got so far, but I am stuck.
Would appreciate your help
trigger test1 on Contact (after insert) { List<SelfServiceUser> newSSU = new List<SelfServiceUser>(); for (Contact c : Trigger.new) { SelfServiceUser s = null; if (c.RecordTypeId == '01220000000135y') { s = new SelfServiceUser(); s.ContactId = c.Id; s.Email = c.Email; s.FirstName = c.FirstName; s.LastName = c.LastName; s.IsActive = true; } newSSU.add(s); } insert newSSU; }
The errors and problems I have are;
1. I get an error as follow:
Severity and Description Path Resource Location Creation Time Id Save error: DML not allowed on SelfServiceUser Test/src/triggers test1.trigger line 23 1238057376540 70
-- I guess I cannot create SSU like this - what is the correct way than?
2. I think that my workflow is wrong, but not sure how to fix.
Would appreciate any help.
Thank you Mak for your sample. I have managed to create a new SSU now as well.
Please find code for .NET This is to be used with Partner API and not Enterprise.
sObject ssu = new sObject(); ssu.type="SelfServiceUser"; System.Xml.XmlElement[] ssuatt = new System.Xml.XmlElement[8]; System.Xml.XmlDocument ssudoc = new System.Xml.XmlDocument(); ssuatt[0] = ssudoc.CreateElement("ContactId"); ssuatt[0].InnerText = newContactID; ssuatt[1] = ssudoc.CreateElement("Email"); ssuatt[1].InnerText = email; ssuatt[2] = ssudoc.CreateElement("LastName"); ssuatt[2].InnerText = email; ssuatt[3] = ssudoc.CreateElement("Username"); ssuatt[3].InnerText = email; ssuatt[4] = ssudoc.CreateElement("IsActive"); ssuatt[4].InnerText = "true"; suatt[5] = ssudoc.CreateElement("LanguageLocaleKey"); ssuatt[5].InnerText = "en_US"; ssuatt[6] = ssudoc.CreateElement("LocaleSidKey"); ssuatt[6].InnerText = "en_US"; ssuatt[7] = ssudoc.CreateElement("TimeZoneSidKey"); ssuatt[7].InnerText = "America/Los_Angeles"; ssu.Any = ssuatt; sObject[] ssusers = new sObject[1]; ssusers[0] = ssu; SaveResult[] ssuSaveRes; try { ssuSaveRes = sf.create(ssusers); } catch { return CreateUserResult.MngmtProviderConnectionError; }
All Answers
Hi Saariko,
DML operations are not supported on SelfServiceUser object. But I have created SelfServiceUser through Java using Apex API.
THanks Mak,
Can you provide the code you used?
How should I approach this than?
Thanks
Hi,
The code I used in Java class is:
SelfServiceUser ssu = new SelfServiceUser();
ssu.setContactId(contactId);
ssu.setEmail(contact.getEmail());
ssu.setFirstName(contact.getFirstName());
ssu.setLastName(contact.getLastName());
ssu.setUsername(contact.getEmail());
ssu.setIsActive(true);
ssu.setLanguageLocaleKey("en_US");
ssu.setLocaleSidKey("en_US");
ssu.setTimeZoneSidKey("America/Los_Angeles");
// Invoke the create call, passing in the SelfServiceUser properties
// and saving the results in a SaveResult object
SelfServiceUser[] insertArray = new SelfServiceUser[1];
insertArray[0] = ssu;
SaveResult[] saveResult = null;
try {
saveResult = binding.create(insertArray);
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
But it depends on your requirement. In my case the requirement was such that on Contact insert, a Java webservice was called which created a new SSP user.
Thank you Mak for your sample. I have managed to create a new SSU now as well.
Please find code for .NET This is to be used with Partner API and not Enterprise.
sObject ssu = new sObject(); ssu.type="SelfServiceUser"; System.Xml.XmlElement[] ssuatt = new System.Xml.XmlElement[8]; System.Xml.XmlDocument ssudoc = new System.Xml.XmlDocument(); ssuatt[0] = ssudoc.CreateElement("ContactId"); ssuatt[0].InnerText = newContactID; ssuatt[1] = ssudoc.CreateElement("Email"); ssuatt[1].InnerText = email; ssuatt[2] = ssudoc.CreateElement("LastName"); ssuatt[2].InnerText = email; ssuatt[3] = ssudoc.CreateElement("Username"); ssuatt[3].InnerText = email; ssuatt[4] = ssudoc.CreateElement("IsActive"); ssuatt[4].InnerText = "true"; suatt[5] = ssudoc.CreateElement("LanguageLocaleKey"); ssuatt[5].InnerText = "en_US"; ssuatt[6] = ssudoc.CreateElement("LocaleSidKey"); ssuatt[6].InnerText = "en_US"; ssuatt[7] = ssudoc.CreateElement("TimeZoneSidKey"); ssuatt[7].InnerText = "America/Los_Angeles"; ssu.Any = ssuatt; sObject[] ssusers = new sObject[1]; ssusers[0] = ssu; SaveResult[] ssuSaveRes; try { ssuSaveRes = sf.create(ssusers); } catch { return CreateUserResult.MngmtProviderConnectionError; }